dzprintf-gnu: Add tests.
[gnulib.git] / m4 / mmap-anon.m4
blob61ca0120dafb0154098bc83b01f6807ac172fe9e
1 # mmap-anon.m4
2 # serial 12
3 dnl Copyright (C) 2005, 2007, 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 # Detect how mmap can be used to create anonymous (not file-backed) memory
9 # mappings.
10 # - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS
11 #   and MAP_ANON exist and have the same value.
12 # - On HP-UX, only MAP_ANONYMOUS exists.
13 # - On Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, only MAP_ANON exists.
14 # - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be
15 #   used.
17 AC_DEFUN_ONCE([gl_FUNC_MMAP_ANON],
19   dnl Persuade glibc <sys/mman.h> to define MAP_ANONYMOUS.
20   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
22   # Check for mmap(). Don't use AC_FUNC_MMAP, because it checks too much: it
23   # fails on HP-UX 11, because MAP_FIXED mappings do not work. But this is
24   # irrelevant for anonymous mappings.
25   AC_CHECK_FUNC([mmap], [gl_have_mmap=yes], [gl_have_mmap=no])
27   # Try to allow MAP_ANONYMOUS.
28   gl_have_mmap_anonymous=no
29   if test $gl_have_mmap = yes; then
30     AC_MSG_CHECKING([for MAP_ANONYMOUS])
31     AC_EGREP_CPP([I cannot identify this map], [
32 #include <sys/mman.h>
33 #ifdef MAP_ANONYMOUS
34     I cannot identify this map
35 #endif
37       [gl_have_mmap_anonymous=yes])
38     if test $gl_have_mmap_anonymous != yes; then
39       AC_EGREP_CPP([I cannot identify this map], [
40 #include <sys/mman.h>
41 #ifdef MAP_ANON
42     I cannot identify this map
43 #endif
45         [AC_DEFINE([MAP_ANONYMOUS], [MAP_ANON],
46           [Define to a substitute value for mmap()'s MAP_ANONYMOUS flag.])
47          gl_have_mmap_anonymous=yes])
48     fi
49     AC_MSG_RESULT([$gl_have_mmap_anonymous])
50     if test $gl_have_mmap_anonymous = yes; then
51       AC_DEFINE([HAVE_MAP_ANONYMOUS], [1],
52         [Define to 1 if mmap()'s MAP_ANONYMOUS flag is available after including
53          config.h and <sys/mman.h>.])
54     fi
55   fi