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