[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Check for `mmap' fails on Cygwin/Windows
From: |
Russ Allbery |
Subject: |
Re: Check for `mmap' fails on Cygwin/Windows |
Date: |
25 Oct 2000 15:56:59 -0700 |
User-agent: |
Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands) |
Akim Demaille <address@hidden> writes:
> Thanks for the patch. I'm not responding because I'm incompetent. In
> addition, Autoconf's checking of mmap has been criticized a lot, and
> it is unclear how the test should be performed (lots of combinations
> which might interest some people and not others).
> I prefer letting Jim, Paul and Alexandre answer this.
For what it's worth, this is what we replaced the check for mmap with for
INN, since it checks something much closer to what we actually do. Note
that we also ripped out all the getpagesize stuff, since a working mmap
should be able to map a memory region of any size, not just a multiple of
the page size (it's the *offset* that has to be a multiple of the page
size).
dnl The set of standard includes, used for checking if functions need to be
dnl declared and for tests that need to use standard functions.
define([_INN_HEADER_SOURCE],
[#include <stdio.h>
#include <sys/types.h>
#if STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# if HAVE_STDLIB_H
# include <stdlib.h>
# endif
# if !HAVE_STRCHR
# define strchr index
# define strrchr rindex
# endif
#endif
#if HAVE_STRING_H
# if !STDC_HEADERS && HAVE_MEMORY_H
# include <memory.h>
# endif
# include <string.h>
#else
# if HAVE_STRINGS_H
# include <strings.h>
# endif
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif])
dnl Source used by INN_FUNC_MMAP.
define([_INN_FUNC_MMAP_SOURCE],
[_INN_HEADER_SOURCE()]
[[#include <fcntl.h>
#include <sys/mman.h>
int
main()
{
int *data, *data2;
int i, fd;
/* First, make a file with some known garbage in it. Use something
larger than one page but still an odd page size. */
data = malloc (20000);
if (!data) return 1;
for (i = 0; i < 20000 / sizeof (int); i++)
data[i] = rand();
umask (0);
fd = creat ("conftestmmaps", 0600);
if (fd < 0) return 1;
if (write (fd, data, 20000) != 20000) return 1;
close (fd);
/* Next, try to mmap the file and make sure we see the same garbage. */
fd = open ("conftestmmaps", O_RDWR);
if (fd < 0) return 1;
data2 = mmap (0, 20000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (data2 == (int *) -1) return 1;
for (i = 0; i < 20000 / sizeof (int); i++)
if (data[i] != data2[i])
return 1;
close (fd);
unlink ("conftestmmaps");
return 0;
}]])
dnl This portion is similar to what AC_FUNC_MMAP does, only it tests shared,
dnl non-fixed mmaps.
AC_DEFUN([INN_FUNC_MMAP],
[AC_CACHE_CHECK(for working mmap, inn_cv_func_mmap,
[AC_TRY_RUN(_INN_FUNC_MMAP_SOURCE(),
inn_cv_func_mmap=yes,
inn_cv_func_mmap=no,
inn_cv_func_mmap=no)])
if test $inn_cv_func_mmap = yes ; then
AC_DEFINE(HAVE_MMAP)
fi])
--
Russ Allbery (address@hidden) <http://www.eyrie.org/~eagle/>