Blame m4/strtok_r.m4

Packit 8f70b4
# strtok_r.m4 serial 15
Packit 8f70b4
dnl Copyright (C) 2002-2004, 2006-2007, 2009-2018 Free Software Foundation,
Packit 8f70b4
dnl Inc.
Packit 8f70b4
dnl This file is free software; the Free Software Foundation
Packit 8f70b4
dnl gives unlimited permission to copy and/or distribute it,
Packit 8f70b4
dnl with or without modifications, as long as this notice is preserved.
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_FUNC_STRTOK_R],
Packit 8f70b4
[
Packit 8f70b4
  dnl The strtok_r() declaration in lib/string.in.h uses 'restrict'.
Packit 8f70b4
  AC_REQUIRE([AC_C_RESTRICT])
Packit 8f70b4
Packit 8f70b4
  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
Packit 8f70b4
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
Packit 8f70b4
  AC_CHECK_FUNCS([strtok_r])
Packit 8f70b4
  if test $ac_cv_func_strtok_r = yes; then
Packit 8f70b4
    HAVE_STRTOK_R=1
Packit 8f70b4
    dnl glibc 2.7 has a bug in strtok_r that causes a segmentation fault
Packit 8f70b4
    dnl when the second argument to strtok_r is a constant string that has
Packit 8f70b4
    dnl exactly one byte and compiling with optimization.  This bug is, for
Packit 8f70b4
    dnl example, present in the glibc 2.7-18 package in Debian "lenny".
Packit 8f70b4
    dnl See <https://sourceware.org/bugzilla/show_bug.cgi?id=5614>.
Packit 8f70b4
    AC_CACHE_CHECK([whether strtok_r works], [gl_cv_func_strtok_r_works],
Packit 8f70b4
      [AC_RUN_IFELSE(
Packit 8f70b4
         [AC_LANG_PROGRAM([[
Packit 8f70b4
              #ifndef __OPTIMIZE__
Packit 8f70b4
              # define __OPTIMIZE__ 1
Packit 8f70b4
              #endif
Packit 8f70b4
              #undef __OPTIMIZE_SIZE__
Packit 8f70b4
              #undef __NO_INLINE__
Packit 8f70b4
              #include <stdlib.h>
Packit 8f70b4
              #include <string.h>
Packit 8f70b4
            ]],
Packit 8f70b4
            [[static const char dummy[] = "\177\01a";
Packit 8f70b4
              char delimiters[] = "xxxxxxxx";
Packit 8f70b4
              char *save_ptr = (char *) dummy;
Packit 8f70b4
              strtok_r (delimiters, "x", &save_ptr);
Packit 8f70b4
              strtok_r (NULL, "x", &save_ptr);
Packit 8f70b4
              return 0;
Packit 8f70b4
            ]])
Packit 8f70b4
         ],
Packit 8f70b4
         [gl_cv_func_strtok_r_works=yes],
Packit 8f70b4
         [gl_cv_func_strtok_r_works=no],
Packit 8f70b4
         [case "$host_os" in
Packit 8f70b4
                           # Guess no on glibc systems.
Packit 8f70b4
            *-gnu* | gnu*) gl_cv_func_strtok_r_works="guessing no" ;;
Packit 8f70b4
                           # Guess yes on native Windows.
Packit 8f70b4
            mingw*)        gl_cv_func_strtok_r_works="guessing yes" ;;
Packit 8f70b4
            *)             gl_cv_func_strtok_r_works="guessing yes" ;;
Packit 8f70b4
          esac
Packit 8f70b4
         ])
Packit 8f70b4
      ])
Packit 8f70b4
    case "$gl_cv_func_strtok_r_works" in
Packit 8f70b4
      *no)
Packit 8f70b4
        dnl We could set REPLACE_STRTOK_R=1 here, but it's only the macro
Packit 8f70b4
        dnl version in <bits/string2.h> which is wrong. The code compiled
Packit 8f70b4
        dnl into libc is fine.
Packit 8f70b4
        UNDEFINE_STRTOK_R=1
Packit 8f70b4
        ;;
Packit 8f70b4
    esac
Packit 8f70b4
  else
Packit 8f70b4
    HAVE_STRTOK_R=0
Packit 8f70b4
  fi
Packit 8f70b4
  AC_CHECK_DECLS_ONCE([strtok_r])
Packit 8f70b4
  if test $ac_cv_have_decl_strtok_r = no; then
Packit 8f70b4
    HAVE_DECL_STRTOK_R=0
Packit 8f70b4
  fi
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
# Prerequisites of lib/strtok_r.c.
Packit 8f70b4
AC_DEFUN([gl_PREREQ_STRTOK_R], [
Packit 8f70b4
  :
Packit 8f70b4
])