Blame m4/strtok_r.m4

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