1 # MAGICK_FUNC_MMAP_FILEIO
3 AC_DEFUN([MAGICK_FUNC_MMAP_FILEIO],
4 [AC_CHECK_HEADERS(stdlib.h unistd.h)
5 AC_CHECK_FUNCS(getpagesize)
6 AC_CACHE_CHECK(for working mmap file i/o, magick_cv_func_mmap_fileio,
7 [AC_RUN_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT]
8 [[/* malloc might have been renamed as rpl_malloc. */
12 This test is derived from GNU Autoconf's similar macro.
13 The purpose of this test is to verify that files may be memory
14 mapped, and that memory mapping and file I/O are coherent.
16 The test creates a test file, memory maps the file, updates
17 the file using the memory map, and then reads the file using
18 file I/O to verify that the file contains the updates.
24 #if !STDC_HEADERS && !HAVE_STDLIB_H
28 /* This mess was copied from the GNU getpagesize.h. */
30 /* Assume that all systems that can run configure have sys/param.h. */
31 # if !HAVE_SYS_PARAM_H
32 # define HAVE_SYS_PARAM_H 1
36 # define getpagesize() sysconf(_SC_PAGESIZE)
37 # else /* no _SC_PAGESIZE */
39 # include <sys/param.h>
41 # define getpagesize() EXEC_PAGESIZE
42 # else /* no EXEC_PAGESIZE */
44 # define getpagesize() NBPG * CLSIZE
47 # endif /* no CLSIZE */
50 # define getpagesize() NBPC
53 # define getpagesize() PAGESIZE
54 # endif /* PAGESIZE */
57 # endif /* no EXEC_PAGESIZE */
58 # else /* no HAVE_SYS_PARAM_H */
59 # define getpagesize() 8192 /* punt totally */
60 # endif /* no HAVE_SYS_PARAM_H */
61 # endif /* no _SC_PAGESIZE */
63 #endif /* no HAVE_GETPAGESIZE */
68 char *data, *data2, *data3;
72 pagesize = getpagesize ();
74 /* First, make a file with some known garbage in it. */
75 data = (char *) malloc (pagesize);
78 for (i = 0; i < pagesize; ++i)
79 *(data + i) = rand ();
81 fd = creat ("conftest.mmap", 0600);
84 if (write (fd, data, pagesize) != pagesize)
88 /* Mmap the file as read/write/shared and verify that we see the
90 fd = open ("conftest.mmap", O_RDWR);
93 data2 = mmap (0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L);
96 for (i = 0; i < pagesize; ++i)
97 if (*(data + i) != *(data2 + i))
100 /* Finally, make sure that changes to the mapped area
101 percolate back to the file as seen by read(). */
102 for (i = 0; i < pagesize; ++i)
103 *(data2 + i) = *(data2 + i) + 1;
104 data3 = (char *) malloc (pagesize);
107 if (read (fd, data3, pagesize) != pagesize)
109 for (i = 0; i < pagesize; ++i)
110 if (*(data2 + i) != *(data3 + i))
115 [magick_cv_func_mmap_fileio=yes],
116 [magick_cv_func_mmap_fileio=no],
117 [magick_cv_func_mmap_fileio=no])])
118 if test $magick_cv_func_mmap_fileio = yes; then
119 AC_DEFINE(HAVE_MMAP_FILEIO, 1,
120 [Define to 1 if you have a working `mmap' system call.])
123 ])# MAGICK_FUNC_MMAP_FILEIO