1
0
mirror of https://https.git.savannah.gnu.org/git/gnulib.git synced 2026-04-28 06:33:36 +00:00

xstrtol tests: Don't rely on is_GNULIB_strtol.

In a testdir, the Gnulib replacement for strtol may be used in gltests/
but not in gllib/.

* tests/test-xstrtol.c (is_GNULIB_strtol): Remove macro.
(main): Accept both behaviours of strtol on all platforms except MSVC.
* tests/test-xstrtoll.c (is_GNULIB_strtol): Remove macro.
This commit is contained in:
Bruno Haible
2026-04-25 18:15:46 +02:00
parent e2fb3d721a
commit 5d9d0509e3
3 changed files with 30 additions and 11 deletions

View File

@@ -1,3 +1,12 @@
2026-04-25 Bruno Haible <bruno@clisp.org>
xstrtol tests: Don't rely on is_GNULIB_strtol.
In a testdir, the Gnulib replacement for strtol may be used in gltests/
but not in gllib/.
* tests/test-xstrtol.c (is_GNULIB_strtol): Remove macro.
(main): Accept both behaviours of strtol on all platforms except MSVC.
* tests/test-xstrtoll.c (is_GNULIB_strtol): Remove macro.
2026-04-25 Bruno Haible <bruno@clisp.org>
regex: Fix link error on macOS and FreeBSD (regression yesterday).

View File

@@ -28,7 +28,6 @@
# define __xstrtol xstrtol
# define __strtol_t long int
# define __spec "ld"
# define is_GNULIB_strtol GNULIB_defined_strtol_function
#endif
/* Don't show the program name in error messages. */
@@ -68,20 +67,32 @@ main (int argc, char **argv)
/* Test an invalid base (undefined behaviour, as documented in xstrtol.h).
Reported by Alejandro Colomar. */
#if !(defined __CYGWIN__ || defined _MSC_VER)
#if !defined _MSC_VER
{
const char input[] = "k";
char *endp = NULL;
__strtol_t val = -17;
strtol_error s_err = __xstrtol (input, &endp, -1, &val, "k");
# if !(defined __GLIBC__ || is_GNULIB_strtol)
ASSERT (s_err == LONGINT_OK);
ASSERT (endp == input + 1);
ASSERT (val == 1024);
# else
ASSERT (s_err == LONGINT_INVALID);
ASSERT (val == -17);
# endif
if (s_err == LONGINT_INVALID)
{
/* On glibc or when the gnulib replacement function is used,
strtol (input, &endp, -1) returns 0 with errno == EINVAL,
*without* changing endp. xstrtol then returns LONGINT_INVALID.
*/
ASSERT (s_err == LONGINT_INVALID);
ASSERT (val == -17);
}
else
{
/* On musl libc, macOS, NetBSD, OpenBSD, Solaris, mingw,
when the gnulib replacement function is not used,
strtol (input, &endp, -1) returns 0 with errno == EINVAL,
setting endp = input. xstrtol then performs the suffix
processing and finally returns LONGINT_OK. */
ASSERT (s_err == LONGINT_OK);
ASSERT (endp == input + 1);
ASSERT (val == 1024);
}
}
#endif

View File

@@ -1,5 +1,4 @@
#define __xstrtol xstrtoll
#define __strtol_t long long int
#define __spec "lld"
#define is_GNULIB_strtol GNULIB_defined_strtoll_function
#include "test-xstrtol.c"