diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 3 | ||||
-rw-r--r-- | lib/strutils.c | 24 |
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 36396a38..0f13237f 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -3,7 +3,7 @@ include $(top_srcdir)/config/include-Makefile.am AM_CPPFLAGS += -DTEST_PROGRAM noinst_PROGRAMS = test_blkdev test_ismounted test_wholedisk test_mangle \ - test_tt test_canonicalize test_at + test_tt test_canonicalize test_at test_strutils if LINUX if HAVE_CPU_SET_T noinst_PROGRAMS += test_cpuset @@ -15,6 +15,7 @@ test_ismounted_SOURCES = ismounted.c test_wholedisk_SOURCES = wholedisk.c test_mangle_SOURCES = mangle.c test_at_SOURCES = at.c +test_strutils_SOURCES = strutils.c if LINUX test_cpuset_SOURCES = cpuset.c endif diff --git a/lib/strutils.c b/lib/strutils.c index e8e86865..9a59e67b 100644 --- a/lib/strutils.c +++ b/lib/strutils.c @@ -273,3 +273,27 @@ char *size_to_human_string(uint64_t bytes) return strdup(buf); } + + +#ifdef TEST_PROGRAM + +#include <stdio.h> +#include <stdlib.h> +#include <err.h> + +int main(int argc, char *argv[]) +{ + uintmax_t size = 0; + + if (argc < 2) { + fprintf(stderr, "usage: %s <number>[suffix]\n", argv[0]); + exit(EXIT_FAILURE); + } + + if (strtosize(argv[1], &size)) + errx(EXIT_FAILURE, "invalid size '%s' value", argv[1]); + + printf("%25s : %20ju\n", argv[1], size); + return EXIT_FAILURE; +} +#endif /* TEST_PROGRAM */ |