]> git.ozlabs.org Git - ccan/commit
opt: functions to show integer values with kMGTPE suffixes
authorDouglas Bagnall <douglas@paradise.net.nz>
Sat, 13 Aug 2011 12:31:42 +0000 (22:01 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Sat, 13 Aug 2011 12:31:42 +0000 (22:01 +0930)
commitbbdf3ef3c2c14e515388c6146fd00557cee905a1
treeed130c357c6528c0931f16be99110d353d7c9955
parentbabb23101ae447aefb65284b8f535f84e6a35008
opt: functions to show integer values with kMGTPE suffixes

As with the set_ functions, there are twelve permutations of integer size,
base, and signedness.  The supported sizes are int, long, and long long.

For example, this:

 char buf1[OPT_SHOW_LEN];
 char buf2[OPT_SHOW_LEN];
 unsigned i = 1024000;
 opt_show_uintval_bi(buf1, &i);
 opt_show_uintval_si(buf2, &i);

will put "1000k" in buf1, and "1024k" in buf2.

Unlike the opt_set_ functions, these use unsigned arithmetic for unsigned values.

(32 bit bug using sizeof(suffixes) instead of strlen(suffixes) fixed by Rusty)
ccan/opt/helpers.c
ccan/opt/opt.h
ccan/opt/test/run-helpers.c