summaryrefslogtreecommitdiff
path: root/m4/memchr.m4
diff options
context:
space:
mode:
Diffstat (limited to 'm4/memchr.m4')
-rw-r--r--m4/memchr.m471
1 files changed, 33 insertions, 38 deletions
diff --git a/m4/memchr.m4 b/m4/memchr.m4
index 91eec88e09..346a288210 100644
--- a/m4/memchr.m4
+++ b/m4/memchr.m4
@@ -1,5 +1,6 @@
-# memchr.m4 serial 15
-dnl Copyright (C) 2002-2004, 2009-2020 Free Software Foundation, Inc.
+# memchr.m4
+# serial 19
+dnl Copyright (C) 2002-2004, 2009-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -13,27 +14,18 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
AC_CHECK_HEADERS_ONCE([sys/mman.h])
AC_CHECK_FUNCS_ONCE([mprotect])
- AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
- m4_ifdef([gl_FUNC_MEMCHR_OBSOLETE], [
- dnl These days, we assume memchr is present. But if support for old
- dnl platforms is desired:
- AC_CHECK_FUNCS_ONCE([memchr])
- if test $ac_cv_func_memchr = no; then
- HAVE_MEMCHR=0
- fi
- ])
- if test $HAVE_MEMCHR = 1; then
- # Detect platform-specific bugs in some versions of glibc:
- # memchr should not dereference anything with length 0
- # https://bugzilla.redhat.com/show_bug.cgi?id=499689
- # memchr should not dereference overestimated length after a match
- # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737
- # https://sourceware.org/bugzilla/show_bug.cgi?id=10162
- # memchr should cast the second argument to 'unsigned char'.
- # This bug exists in Android 4.3.
- # Assume that memchr works on platforms that lack mprotect.
- AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works],
- [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+ AC_REQUIRE([gl_STRING_H_DEFAULTS])
+ # Detect platform-specific bugs in some versions of glibc:
+ # memchr should not dereference anything with length 0
+ # https://bugzilla.redhat.com/show_bug.cgi?id=499689
+ # memchr should not dereference overestimated length after a match
+ # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737
+ # https://sourceware.org/bugzilla/show_bug.cgi?id=10162
+ # memchr should cast the second argument to 'unsigned char'.
+ # This bug exists in Android 4.3.
+ # Assume that memchr works on platforms that lack mprotect.
+ AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works],
+ [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <string.h>
#if HAVE_SYS_MMAN_H
# include <fcntl.h>
@@ -68,6 +60,7 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
#endif
if (fence)
{
+ /* Test against bugs on glibc systems. */
if (memchr (fence, 0, 0))
result |= 1;
strcpy (fence - 9, "12345678");
@@ -75,6 +68,9 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
result |= 2;
if (memchr (fence - 1, 0, 3) != fence - 1)
result |= 4;
+ /* Test against bug on AIX 7.2. */
+ if (memchr (fence - 4, '6', 16) != fence - 4)
+ result |= 8;
}
/* Test against bug on Android 4.3. */
{
@@ -83,27 +79,26 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
input[1] = 'b';
input[2] = 'c';
if (memchr (input, 0x789abc00 | 'b', 3) != input + 1)
- result |= 8;
+ result |= 16;
}
return result;
]])],
- [gl_cv_func_memchr_works=yes],
- [gl_cv_func_memchr_works=no],
- [case "$host_os" in
+ [gl_cv_func_memchr_works=yes],
+ [gl_cv_func_memchr_works=no],
+ [case "$host_os" in
# Guess no on Android.
- linux*-android*) gl_cv_func_memchr_works="guessing no" ;;
+ linux*-android*) gl_cv_func_memchr_works="guessing no" ;;
# Guess yes on native Windows.
- mingw*) gl_cv_func_memchr_works="guessing yes" ;;
+ mingw* | windows*) gl_cv_func_memchr_works="guessing yes" ;;
# If we don't know, obey --enable-cross-guesses.
- *) gl_cv_func_memchr_works="$gl_cross_guess_normal" ;;
- esac
- ])
- ])
- case "$gl_cv_func_memchr_works" in
- *yes) ;;
- *) REPLACE_MEMCHR=1 ;;
- esac
- fi
+ *) gl_cv_func_memchr_works="$gl_cross_guess_normal" ;;
+ esac
+ ])
+ ])
+ case "$gl_cv_func_memchr_works" in
+ *yes) ;;
+ *) REPLACE_MEMCHR=1 ;;
+ esac
])
# Prerequisites of lib/memchr.c.

Return to:

Send suggestions and report system problems to the System administrator.