Reid Spencer | 491f681 | 2004-09-07 06:56:14 +0000 | [diff] [blame] | 1 | # |
| 2 | # Check for the ability to mmap a file. |
| 3 | # |
| 4 | AC_DEFUN([AC_FUNC_MMAP_FILE], |
| 5 | [AC_CACHE_CHECK(for mmap of files, |
| 6 | ac_cv_func_mmap_file, |
Reid Spencer | 12de17d | 2004-09-19 22:31:49 +0000 | [diff] [blame] | 7 | [ AC_LANG_PUSH([C]) |
| 8 | AC_RUN_IFELSE([ |
Reid Spencer | a42b525 | 2004-09-20 04:08:22 +0000 | [diff] [blame] | 9 | AC_LANG_PROGRAM([[ |
Reid Spencer | 491f681 | 2004-09-07 06:56:14 +0000 | [diff] [blame] | 10 | #include <sys/types.h> |
Reid Spencer | 491f681 | 2004-09-07 06:56:14 +0000 | [diff] [blame] | 11 | #include <sys/mman.h> |
Reid Spencer | 491f681 | 2004-09-07 06:56:14 +0000 | [diff] [blame] | 12 | #include <fcntl.h> |
Reid Spencer | a42b525 | 2004-09-20 04:08:22 +0000 | [diff] [blame] | 13 | ]],[[ |
Reid Spencer | 491f681 | 2004-09-07 06:56:14 +0000 | [diff] [blame] | 14 | int fd; |
Reid Spencer | a42b525 | 2004-09-20 04:08:22 +0000 | [diff] [blame] | 15 | fd = creat ("foo",0777); |
| 16 | fd = (int) mmap (0, 1, PROT_READ, MAP_SHARED, fd, 0); |
| 17 | unlink ("foo"); |
Reid Spencer | 91b5380 | 2004-09-21 17:10:52 +0000 | [diff] [blame] | 18 | return (fd != (int) MAP_FAILED);]])], |
| 19 | [ac_cv_func_mmap_file=yes],[ac_cv_func_mmap_file=no],[ac_cv_func_mmap_file=no]) |
Reid Spencer | 12de17d | 2004-09-19 22:31:49 +0000 | [diff] [blame] | 20 | AC_LANG_POP([C]) |
Reid Spencer | 491f681 | 2004-09-07 06:56:14 +0000 | [diff] [blame] | 21 | ]) |
| 22 | if test "$ac_cv_func_mmap_file" = yes; then |
| 23 | AC_DEFINE([HAVE_MMAP_FILE],[],[Define if mmap() can map files into memory]) |
| 24 | AC_SUBST(MMAP_FILE,[yes]) |
| 25 | fi |
| 26 | ]) |