diff options
author | Karel Zak | 2011-01-01 22:45:29 +0100 |
---|---|---|
committer | Karel Zak | 2011-01-03 12:28:48 +0100 |
commit | 013bff51a67fe5907532639d35f9d9f1df2c7570 (patch) | |
tree | f270146bbbcf19679c993ce1d0be62f03d4cd4e8 /lib | |
parent | findmnt: add MAJ:MIN (diff) | |
download | kernel-qcow2-util-linux-013bff51a67fe5907532639d35f9d9f1df2c7570.tar.gz kernel-qcow2-util-linux-013bff51a67fe5907532639d35f9d9f1df2c7570.tar.xz kernel-qcow2-util-linux-013bff51a67fe5907532639d35f9d9f1df2c7570.zip |
tests: fix strtosize() test
Signed-off-by: Karel Zak <kzak@redhat.com>
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 36396a385..0f13237f7 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 e8e868653..9a59e67b6 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 */ |