Tag
Hash :
e9c57721
Author :
Date :
2007-08-10T19:02:31
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal. * lib/xstrtol.h: Don't include exitfail.h; that's now internal to xstrtol.c. Include getopt.h, since xstrtol_fatal's signature depends on it. (xstrtol_error): Remove. (xstrtol_fatal): New decl, replacing the functionality of xstrtol_error but with a different signature. (ATTRIBUTE_NORETURN, __attribute__): New macros. * lib/xstrtol-error.c: Include exitfail.h. (xstrtol_fatal): New function, with a different signature from the old xstrtol_error, so that the caller need not worry about passing in an exit status, or about storage management of the option argument. (xstrtol_error): Now a static function. Redo signature to implement xstrtol_fatal. Output the correct number of hyphens in front of the option so that the caller need not worry about storage management. (N_): New macro. (_): Remove; not used now. * modules/xstrtol: Depend on getopt. * tests/test-xstrtol.c (main): Use new xstrtol_error function instead of old STRTOL_FATAL_ERROR macro. * tests/test-xstrtol.sh (t-xstrtol.xo): Adjust to match new behavior of test program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#!/bin/sh
tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15
tmpfiles="t-xstrtol.tmp t-xstrtol.xo"
: > t-xstrtol.tmp
too_big=99999999999999999999999999999999999999999999999999999999999999999999
result=0
# test xstrtol
./test-xstrtol${EXEEXT} 1 >> t-xstrtol.tmp 2>&1 || result=1
./test-xstrtol${EXEEXT} -1 >> t-xstrtol.tmp 2>&1 || result=1
./test-xstrtol${EXEEXT} 1k >> t-xstrtol.tmp 2>&1 || result=1
./test-xstrtol${EXEEXT} ${too_big}h >> t-xstrtol.tmp 2>&1 && result=1
./test-xstrtol${EXEEXT} $too_big >> t-xstrtol.tmp 2>&1 && result=1
./test-xstrtol${EXEEXT} x >> t-xstrtol.tmp 2>&1 && result=1
./test-xstrtol${EXEEXT} 9x >> t-xstrtol.tmp 2>&1 && result=1
./test-xstrtol${EXEEXT} 010 >> t-xstrtol.tmp 2>&1 || result=1
# suffix without integer is valid
./test-xstrtol${EXEEXT} MiB >> t-xstrtol.tmp 2>&1 || result=1
# test xstrtoul
./test-xstrtoul${EXEEXT} 1 >> t-xstrtol.tmp 2>&1 || result=1
./test-xstrtoul${EXEEXT} -1 >> t-xstrtol.tmp 2>&1 && result=1
./test-xstrtoul${EXEEXT} 1k >> t-xstrtol.tmp 2>&1 || result=1
./test-xstrtoul${EXEEXT} ${too_big}h >> t-xstrtol.tmp 2>&1 && result=1
./test-xstrtoul${EXEEXT} $too_big >> t-xstrtol.tmp 2>&1 && result=1
./test-xstrtoul${EXEEXT} x >> t-xstrtol.tmp 2>&1 && result=1
./test-xstrtoul${EXEEXT} 9x >> t-xstrtol.tmp 2>&1 && result=1
./test-xstrtoul${EXEEXT} 010 >> t-xstrtol.tmp 2>&1 || result=1
./test-xstrtoul${EXEEXT} MiB >> t-xstrtol.tmp 2>&1 || result=1
# normalize output
sed -e 's/^[^:]*: //' < t-xstrtol.tmp > t-xstrtol.xo
mv t-xstrtol.xo t-xstrtol.tmp
# compare expected output
cat > t-xstrtol.xo <<EOF
1->1 ()
-1->-1 ()
1k->1024 ()
invalid suffix in X argument \`${too_big}h'
X argument \`$too_big' too large
invalid X argument \`x'
invalid suffix in X argument \`9x'
010->8 ()
MiB->1048576 ()
1->1 ()
invalid X argument \`-1'
1k->1024 ()
invalid suffix in X argument \`${too_big}h'
X argument \`$too_big' too large
invalid X argument \`x'
invalid suffix in X argument \`9x'
010->8 ()
MiB->1048576 ()
EOF
diff t-xstrtol.xo t-xstrtol.tmp || result=1
rm -fr $tmpfiles
exit $result