This is release 201002.1
[nobug.git] / m4 / mmap-anon.m4
blob1138ccd83e8666ed5923e84db5309a3768df2121
1 # mmap-anon.m4 serial 8
2 dnl Copyright (C) 2009 Christian Thaeter <ct@pipapo.org>
3 dnl parts are borrowed from gnulib:
4 dnl Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
5 dnl This file is free software; the Free Software Foundation
6 dnl gives unlimited permission to copy and/or distribute it,
7 dnl with or without modifications, as long as this notice is preserved.
9 # Detect how mmap can be used to create anonymous (not file-backed) memory
10 # mappings.
11 # - On Linux, AIX, OSF/1, Solaris, Cygwin, Interix, Haiku, both MAP_ANONYMOUS
12 #   and MAP_ANON exist and have the same value.
13 # - On HP-UX, only MAP_ANONYMOUS exists.
14 # - On MacOS X, FreeBSD, NetBSD, OpenBSD, only MAP_ANON exists.
15 # - On IRIX, neither exists, and a file descriptor opened to /dev/zero must be
16 #   used.
18 AC_DEFUN([nobug_FUNC_MMAP_ANON],
20   dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57.
21   AC_REQUIRE([AC_PROG_CPP])
22   AC_REQUIRE([AC_PROG_EGREP])
24   AC_FUNC_MMAP
26   # Try to allow MAP_ANONYMOUS.
27   nobug_have_mmap_anonymous=no
28   if test x$ac_cv_func_mmap_fixed_mapped = xyes; then
29     AC_MSG_CHECKING([for MAP_ANONYMOUS])
30     AC_EGREP_CPP([I cant identify this map.],
32 #include <sys/mman.h>
33 #ifdef MAP_ANONYMOUS
34     I cant identify this map.
35 #endif
37       [nobug_have_mmap_anonymous=yes])
38     if test $nobug_have_mmap_anonymous != yes; then
39       AC_EGREP_CPP([I cant identify this map.],
41 #include <sys/mman.h>
42 #ifdef MAP_ANON
43     I cant identify this map.
44 #endif
46         [AC_DEFINE([MAP_ANONYMOUS], [MAP_ANON],
47           [Define to a substitute value for mmaps MAP_ANONYMOUS flag.])
48          nobug_have_mmap_anonymous=yes])
49     fi
50     AC_MSG_RESULT([$nobug_have_mmap_anonymous])
51     if test $nobug_have_mmap_anonymous = yes; then
52       AC_DEFINE([HAVE_MAP_ANONYMOUS], [1],
53         [Define to 1 if mmaps MAP_ANONYMOUS flag is available.])
54     fi
55   fi