2N/Adnl Copyright (C) 2002-2004, 2009-2010 Free Software Foundation, Inc.
2N/Adnl This file is free software; the Free Software Foundation
2N/Adnl gives unlimited permission to copy
and/or distribute it,
2N/Adnl with or without modifications, as long as this notice is preserved.
2N/AAC_DEFUN_ONCE([gl_FUNC_MEMCHR],
2N/A dnl Check for prerequisites for memory fence checks.
2N/A AC_CHECK_FUNCS_ONCE([mprotect])
2N/A dnl These days, we assume memchr is present. But just in case...
2N/A AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
2N/A AC_CHECK_FUNCS_ONCE([memchr])
2N/A if test $ac_cv_func_memchr = yes; then
2N/A # Detect platform-specific bugs in some versions of glibc:
2N/A # memchr should not dereference anything with length 0
2N/A # memchr should not dereference overestimated length after a match
2N/A # Assume that memchr works on platforms that lack mprotect.
2N/A AC_CACHE_CHECK([whether memchr works], [gl_cv_func_memchr_works],
2N/A [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
2N/A#if HAVE_SYS_MMAN_H && HAVE_MPROTECT
2N/A# if HAVE_MAP_ANONYMOUS
2N/A const int flags = MAP_ANONYMOUS | MAP_PRIVATE;
2N/A# else /* !HAVE_MAP_ANONYMOUS */
2N/A const int flags = MAP_FILE | MAP_PRIVATE;
2N/A int pagesize = getpagesize ();
2N/A (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE,
2N/A if (two_pages != (char *)(-1)
2N/A && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0)
2N/A fence = two_pages + pagesize;
2N/A if (memchr (fence, 0, 0))
2N/A strcpy (fence - 9, "12345678");
2N/A if (memchr (fence - 9, 0, 79) != fence - 1)
2N/A if (memchr (fence - 1, 0, 3) != fence - 1)
2N/A]])], [gl_cv_func_memchr_works=yes], [gl_cv_func_memchr_works=no],
2N/A [dnl Be pessimistic for now.
2N/A gl_cv_func_memchr_works="guessing no"])])
2N/A if test "$gl_cv_func_memchr_works" != yes; then
2N/A if test $HAVE_MEMCHR = 0 || test $REPLACE_MEMCHR = 1; then
2N/AAC_DEFUN([gl_PREREQ_MEMCHR], [