[git commit prelink 1/1] libc: fix strtoq

Natanael Copa natanael.copa at gmail.com
Tue Dec 14 07:08:36 UTC 2010


commit: http://git.uclibc.org/uClibc/commit/?id=78009d25addb8487702f902ed4ad581a5004bfe9
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/prelink

strtoq should always return a quad_t and be an alias of strtol on
64 bit and strtoll on 32 bit.

Signed-off-by: Natanael Copa <natanael.copa at gmail.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 include/stdlib.h         |    2 +-
 libc/stdlib/stdlib.c     |    3 ++
 test/.gitignore          |    1 +
 test/stdlib/teststrtoq.c |   89 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 94 insertions(+), 1 deletions(-)
 create mode 100644 test/stdlib/teststrtoq.c

diff --git a/include/stdlib.h b/include/stdlib.h
index ce92ccd..300edf0 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -214,7 +214,7 @@ __END_NAMESPACE_STD
 
 /* Convert a string to a quadword integer.  */
 __extension__
-extern long long int strtoq (__const char *__restrict __nptr,
+extern quad_t strtoq (__const char *__restrict __nptr,
 			     char **__restrict __endptr, int __base)
      __THROW __nonnull ((1)) __wur;
 /* Convert a string to an unsigned quadword integer.  */
diff --git a/libc/stdlib/stdlib.c b/libc/stdlib/stdlib.c
index ad0c4aa..4d608ee 100644
--- a/libc/stdlib/stdlib.c
+++ b/libc/stdlib/stdlib.c
@@ -342,6 +342,9 @@ extern __typeof(__XL_NPP(strtol)) __XL_NPP(strtoll);
 libc_hidden_proto(__XL_NPP(strtoll))
 strong_alias(__XL_NPP(strtol),__XL_NPP(strtoll))
 libc_hidden_def(__XL_NPP(strtoll))
+#if !defined(L_strtol_l)
+strong_alias(strtol,strtoq)
+#endif
 #endif
 
 #endif
diff --git a/test/.gitignore b/test/.gitignore
index 605d16d..991ce5f 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -256,6 +256,7 @@ stdlib/test-canon
 stdlib/test-canon2
 stdlib/teston_exit
 stdlib/teststrtol
+stdlib/teststrtoq
 string/bug-strcoll1
 string/bug-strncat1
 string/bug-strpbrk1
diff --git a/test/stdlib/teststrtoq.c b/test/stdlib/teststrtoq.c
new file mode 100644
index 0000000..6e1a4cb
--- /dev/null
+++ b/test/stdlib/teststrtoq.c
@@ -0,0 +1,89 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+
+
+const char *strings[]={
+	/* some simple stuff */
+	"0", "1", "10",
+	"100", "1000", "10000", "100000", "1000000",
+	"10000000", "100000000", "1000000000",
+
+	/* negative */
+	"-0", "-1", "-10",
+	"-100", "-1000", "-10000", "-100000", "-1000000",
+	"-10000000", "-100000000", "-1000000000",
+
+	/* test base>10 */
+	"a", "b", "f", "g", "z",
+
+	/* test hex */
+	"0x0", "0x1", "0xa", "0xf", "0x10",
+
+	/* test octal */
+	"00", "01", "07", "08", "0a", "010",
+
+	/* other */
+	"0x8000000",
+
+	/* check overflow cases: (for 32 bit) */
+	"2147483645",
+	"2147483646",
+	"2147483647",
+	"2147483648",
+	"2147483649",
+	"-2147483645",
+	"-2147483646",
+	"-2147483647",
+	"-2147483648",
+	"-2147483649",
+	"4294967293",
+	"4294967294",
+	"4294967295",
+	"4294967296",
+	"4294967297",
+	"-4294967293",
+	"-4294967294",
+	"-4294967295",
+	"-4294967296",
+	"-4294967297",
+
+	/* bad input tests */
+	"",
+	"00",
+	"0x",
+	"0x0",
+	"-",
+	"+",
+	" ",
+	" -",
+	" - 0",
+};
+int n_tests=sizeof(strings)/sizeof(strings[0]);
+
+
+
+void do_test(int base);
+void do_test(int base)
+{
+	int i;
+	quad_t n;
+	char *endptr;
+
+	for(i=0;i<n_tests;i++){
+		n=strtoq(strings[i],&endptr,base);
+		printf("strtoq(\"%s\",%d) len=%lu res=%qd\n",
+			strings[i],base,(unsigned long)(endptr-strings[i]),n);
+	}
+}
+
+int main(int argc,char *argv[])
+{
+	do_test(0);
+	do_test(8);
+	do_test(10);
+	do_test(16);
+	do_test(36);
+
+	return 0;
+}
-- 
1.7.2.2



More information about the uClibc-cvs mailing list