summaryrefslogtreecommitdiff
path: root/tests/test-strtoll.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2021-04-02 20:46:15 +0200
committerBruno Haible <bruno@clisp.org>2021-04-02 20:46:15 +0200
commitea1816fd6d334b4bfd8368a63d9bda3cad1c9b0d (patch)
tree68ad3316295d89b4d4e54ba1f6dedabf2f258b1a /tests/test-strtoll.c
parent705c23696fcaf5bd9d4f0aaecd106b4a2c1417b2 (diff)
downloadgnulib-ea1816fd6d334b4bfd8368a63d9bda3cad1c9b0d.tar.gz
strtoll: Work around a bug on native Windows and Minix.
* lib/stdlib.in.h (strtoll): Override if REPLACE_STRTOLL is 1. * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize REPLACE_STRTOLL. * m4/strtoll.m4 (gl_FUNC_STRTOLL): Test whether strtoll works. Set REPLACE_STRTOLL. * modules/stdlib (Makefile.am): Substitute REPLACE_STRTOLL. * modules/strtoll (configure.ac): Test REPLACE_STRTOLL. * tests/test-strtoll.c (main): Add tests of hexadecimal integer syntax. * doc/posix-functions/strtoll.texi: Mention the bug.
Diffstat (limited to 'tests/test-strtoll.c')
-rw-r--r--tests/test-strtoll.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test-strtoll.c b/tests/test-strtoll.c
index ad43fc6f56..5f2b19331f 100644
--- a/tests/test-strtoll.c
+++ b/tests/test-strtoll.c
@@ -177,5 +177,67 @@ main (void)
ASSERT (errno == 0);
}
+ /* Hexadecimal integer syntax. */
+ {
+ const char input[] = "0x2A";
+ char *ptr;
+ long long result;
+ errno = 0;
+ result = strtoll (input, &ptr, 10);
+ ASSERT (result == 0LL);
+ ASSERT (ptr == input + 1);
+ ASSERT (errno == 0);
+ }
+ {
+ const char input[] = "0x2A";
+ char *ptr;
+ long long result;
+ errno = 0;
+ result = strtoll (input, &ptr, 16);
+ ASSERT (result == 42LL);
+ ASSERT (ptr == input + 4);
+ ASSERT (errno == 0);
+ }
+ {
+ const char input[] = "0x2A";
+ char *ptr;
+ long long result;
+ errno = 0;
+ result = strtoll (input, &ptr, 0);
+ ASSERT (result == 42LL);
+ ASSERT (ptr == input + 4);
+ ASSERT (errno == 0);
+ }
+ {
+ const char input[] = "0x";
+ char *ptr;
+ long long result;
+ errno = 0;
+ result = strtoll (input, &ptr, 10);
+ ASSERT (result == 0LL);
+ ASSERT (ptr == input + 1);
+ ASSERT (errno == 0);
+ }
+ {
+ const char input[] = "0x";
+ char *ptr;
+ long long result;
+ errno = 0;
+ result = strtoll (input, &ptr, 16);
+ ASSERT (result == 0LL);
+ ASSERT (ptr == input + 1);
+ ASSERT (errno == 0);
+ }
+ {
+ const char input[] = "0x";
+ char *ptr;
+ long long result;
+ errno = 0;
+ result = strtoll (input, &ptr, 0);
+ ASSERT (result == 0LL);
+ ASSERT (ptr == input + 1);
+ ASSERT (errno == 0);
+ }
+
return 0;
}