diff options
author | Bruno Haible <bruno@clisp.org> | 2021-04-02 20:42:13 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2021-04-02 20:42:13 +0200 |
commit | 705c23696fcaf5bd9d4f0aaecd106b4a2c1417b2 (patch) | |
tree | 44bd091848a15c9d7bf43f6230982491bd449709 /tests | |
parent | 837ffb5ee4585ce6947e1013d03c7d6f21cbd635 (diff) | |
download | gnulib-705c23696fcaf5bd9d4f0aaecd106b4a2c1417b2.tar.gz |
strtol: Work around a bug on native Windows and Minix.
* lib/stdlib.in.h (strtol): New declaration.
* m4/stdlib_h.m4 (gl_STDLIB_H): Test whether strtol is declared.
(gl_STDLIB_H_DEFAULTS): Initialize GNULIB_STRTOL, HAVE_STRTOL,
REPLACE_STRTOL.
* m4/strtol.m4 (gl_FUNC_STRTOL): Require gl_STDLIB_H_DEFAULTS. Test
whether strtol works. Set REPLACE_STRTOL.
* modules/stdlib (Makefile.am): Substitute GNULIB_STRTOL, HAVE_STRTOL,
REPLACE_STRTOL.
* modules/strtol (Status, Notice): Remove.
(Depends-on): Add stdlib.
(configure.ac): Test HAVE_STRTOL and REPLACE_STRTOL. Invoke
gl_STDLIB_MODULE_INDICATOR.
* tests/test-strtol.c (main): Add tests of hexadecimal integer syntax.
* doc/posix-functions/strtol.texi: Mention the bug.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-strtol.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/test-strtol.c b/tests/test-strtol.c index 105bc588bb..467514c6c3 100644 --- a/tests/test-strtol.c +++ b/tests/test-strtol.c @@ -177,5 +177,67 @@ main (void) ASSERT (errno == 0); } + /* Hexadecimal integer syntax. */ + { + const char input[] = "0x2A"; + char *ptr; + long result; + errno = 0; + result = strtol (input, &ptr, 10); + ASSERT (result == 0L); + ASSERT (ptr == input + 1); + ASSERT (errno == 0); + } + { + const char input[] = "0x2A"; + char *ptr; + long result; + errno = 0; + result = strtol (input, &ptr, 16); + ASSERT (result == 42L); + ASSERT (ptr == input + 4); + ASSERT (errno == 0); + } + { + const char input[] = "0x2A"; + char *ptr; + long result; + errno = 0; + result = strtol (input, &ptr, 0); + ASSERT (result == 42L); + ASSERT (ptr == input + 4); + ASSERT (errno == 0); + } + { + const char input[] = "0x"; + char *ptr; + long result; + errno = 0; + result = strtol (input, &ptr, 10); + ASSERT (result == 0L); + ASSERT (ptr == input + 1); + ASSERT (errno == 0); + } + { + const char input[] = "0x"; + char *ptr; + long result; + errno = 0; + result = strtol (input, &ptr, 16); + ASSERT (result == 0L); + ASSERT (ptr == input + 1); + ASSERT (errno == 0); + } + { + const char input[] = "0x"; + char *ptr; + long result; + errno = 0; + result = strtol (input, &ptr, 0); + ASSERT (result == 0L); + ASSERT (ptr == input + 1); + ASSERT (errno == 0); + } + return 0; } |