*printf-posix-tests: Strengthen tests.
[gnulib.git] / m4 / strtol.m4
blob5fd1bcd276c45bc758f5969b28801f3886aa82a2
1 # strtol.m4
2 # serial 10
3 dnl Copyright (C) 2002-2003, 2006, 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_STRTOL],
10   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
11   AC_REQUIRE([AC_CANONICAL_HOST])
12   AC_CHECK_FUNCS([strtol])
13   if test $ac_cv_func_strtol = yes; then
14     AC_CACHE_CHECK([whether strtol works],
15       [gl_cv_func_strtol_works],
16       [AC_RUN_IFELSE(
17          [AC_LANG_PROGRAM(
18             [[#include <stdlib.h>]],
19             [[int result = 0;
20               char *term;
21               /* This test fails on Minix and native Windows.  */
22               {
23                 static char const input[2][3] = {"0x", "0b"};
24                 static int const base[] = {0, 2, 10};
25                 int i, j;
26                 for (i = 0; i < 2; i++)
27                   for (j = 0; j < 3; j++)
28                     {
29                       (void) strtol (input[i], &term, base[j]);
30                       if (term != input[i] + 1)
31                         result |= 1;
32                     }
33               }
34               /* This test fails on pre-C23 platforms.  */
35               {
36                 const char input[] = "0b1";
37                 (void) strtol (input, &term, 2);
38                 if (term != input + 3)
39                   result |= 2;
40               }
41               return result;
42             ]])
43          ],
44          [gl_cv_func_strtol_works=yes],
45          [gl_cv_func_strtol_works=no],
46          [case "$host_os" in
47                                 # Guess no on native Windows.
48             mingw* | windows*)  gl_cv_func_strtol_works="guessing no" ;;
49                                 # Guess no on glibc systems.
50             *-gnu* | gnu*)      gl_cv_func_strtol_works="guessing no" ;;
51                                 # Guess no on musl systems.
52             *-musl* | midipix*) gl_cv_func_strtol_works="guessing no" ;;
53             *)                  gl_cv_func_strtol_works="$gl_cross_guess_normal" ;;
54           esac
55          ])
56     ])
57     case "$gl_cv_func_strtol_works" in
58       *yes) ;;
59       *)    REPLACE_STRTOL=1 ;;
60     esac
61   else
62     HAVE_STRTOL=0
63   fi