file-has-acl: improve performance on Linux symlinks
[gnulib.git] / m4 / strtok_r.m4
blob2ee40c61d8f6bff2ed9e03a605d63e541c574d86
1 # strtok_r.m4
2 # serial 17
3 dnl Copyright (C) 2002-2004, 2006-2007, 2009-2024 Free Software Foundation,
4 dnl Inc.
5 dnl This file is free software; the Free Software Foundation
6 dnl gives unlimited permission to copy and/or distribute it,
7 dnl with or without modifications, as long as this notice is preserved.
9 AC_DEFUN([gl_FUNC_STRTOK_R],
11   dnl The strtok_r() declaration in lib/string.in.h uses 'restrict'.
12   AC_REQUIRE([AC_C_RESTRICT])
14   AC_REQUIRE([gl_STRING_H_DEFAULTS])
15   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
16   AC_CHECK_FUNCS([strtok_r])
17   if test $ac_cv_func_strtok_r = yes; then
18     HAVE_STRTOK_R=1
19     dnl glibc 2.7 has a bug in strtok_r that causes a segmentation fault
20     dnl when the second argument to strtok_r is a constant string that has
21     dnl exactly one byte and compiling with optimization.  This bug is, for
22     dnl example, present in the glibc 2.7-18 package in Debian "lenny".
23     dnl See <https://sourceware.org/bugzilla/show_bug.cgi?id=5614>.
24     AC_CACHE_CHECK([whether strtok_r works], [gl_cv_func_strtok_r_works],
25       [AC_RUN_IFELSE(
26          [AC_LANG_PROGRAM([[
27               #ifndef __OPTIMIZE__
28               # define __OPTIMIZE__ 1
29               #endif
30               #undef __OPTIMIZE_SIZE__
31               #undef __NO_INLINE__
32               #include <stdlib.h>
33               #include <string.h>
34             ]],
35             [[static const char dummy[] = "\177\01a";
36               char delimiters[] = "xxxxxxxx";
37               char *save_ptr = (char *) dummy;
38               strtok_r (delimiters, "x", &save_ptr);
39               strtok_r (NULL, "x", &save_ptr);
40               return 0;
41             ]])
42          ],
43          [gl_cv_func_strtok_r_works=yes],
44          [gl_cv_func_strtok_r_works=no],
45          [case "$host_os" in
46                                # Guess no on glibc systems.
47             *-gnu* | gnu*)     gl_cv_func_strtok_r_works="guessing no" ;;
48                                # Guess yes on native Windows.
49             mingw* | windows*) gl_cv_func_strtok_r_works="guessing yes" ;;
50             *)                 gl_cv_func_strtok_r_works="guessing yes" ;;
51           esac
52          ])
53       ])
54     case "$gl_cv_func_strtok_r_works" in
55       *no)
56         dnl We could set REPLACE_STRTOK_R=1 here, but it's only the macro
57         dnl version in <bits/string2.h> which is wrong. The code compiled
58         dnl into libc is fine.
59         UNDEFINE_STRTOK_R=1
60         ;;
61     esac
62   else
63     HAVE_STRTOK_R=0
64   fi
65   AC_CHECK_DECLS_ONCE([strtok_r])
66   if test $ac_cv_have_decl_strtok_r = no; then
67     HAVE_DECL_STRTOK_R=0
68   fi
71 # Prerequisites of lib/strtok_r.c.
72 AC_DEFUN([gl_PREREQ_STRTOK_R], [
73   :