opt: add integer helpers that accept k, M, G, T, P, E suffixes
These functions come in two flavours: those ending with "_si", which have 1000-based interpretations of the suffixes; and those ending with "_bi", which use base 1024. There are versions for signed and unsigned int, long, and long long destinations, with tests for all 12 new functions. The tests get a bit repetitive, I am afraid. As an example, if the -x option were using the opt_set_intval_bi function, then all of these would do the same thing: $ foo -x 5M $ foo -x $((5 * 1024 * 1024)) $ foo -x 5242880 $ foo -x 5120k quite what that thing is depends on the size of your int -- people with 16 bit ints would see an "out of range" error message. The arithmetic for unsigned variations is actually done using signed long long integers, so the maximum possible value is LLONG_MAX, not ULLONG_MAX. This follows the practice of existing functions, and avoids tedious work.
Showing
This diff is collapsed.
Please register or sign in to comment