@@ -68,20 +68,32 @@ main (int argc, char **argv)
6868
6969 /* Test an invalid base (undefined behaviour, as documented in xstrtol.h).
7070 Reported by Alejandro Colomar. */
71- #if !(defined __CYGWIN__ || defined _MSC_VER )
71+ #if 1 // !(defined __CYGWIN__ || defined _MSC_VER)
7272 {
7373 const char input [] = "k" ;
7474 char * endp = NULL ;
7575 __strtol_t val = -17 ;
7676 strtol_error s_err = __xstrtol (input , & endp , -1 , & val , "k" );
77- # if !(defined __GLIBC__ || is_GNULIB_strtol )
78- ASSERT (s_err == LONGINT_OK );
79- ASSERT (endp == input + 1 );
80- ASSERT (val == 1024 );
81- # else
82- ASSERT (s_err == LONGINT_INVALID );
83- ASSERT (val == -17 );
84- # endif
77+ if (s_err == LONGINT_INVALID )
78+ {
79+ /* On glibc or when the gnulib replacement function is used,
80+ strtol (input, &endp, -1) returns 0 with errno == EINVAL,
81+ *without* changing endp. xstrtol then returns LONGINT_INVALID.
82+ */
83+ ASSERT (s_err == LONGINT_INVALID );
84+ ASSERT (val == -17 );
85+ }
86+ else
87+ {
88+ /* On musl libc, macOS, NetBSD, OpenBSD, Solaris, mingw,
89+ when the gnulib replacement function is not used,
90+ strtol (input, &endp, -1) returns 0 with errno == EINVAL,
91+ setting endp = input. xstrtol then performs the suffix
92+ processing and finally returns LONGINT_OK. */
93+ ASSERT (s_err == LONGINT_OK );
94+ ASSERT (endp == input + 1 );
95+ ASSERT (val == 1024 );
96+ }
8597 }
8698#endif
8799
0 commit comments