Line data Source code
1 : /* Copyright (C) 1989-2014 Free Software Foundation, Inc. 2 : Written by James Clark (jjc@jclark.com) 3 : 4 : This file is part of groff, the GNU roff typesetting system. 5 : 6 : groff is free software; you can redistribute it and/or modify it under 7 : the terms of the GNU General Public License as published by the Free 8 : Software Foundation, either version 3 of the License, or 9 : (at your option) any later version. 10 : 11 : groff is distributed in the hope that it will be useful, but WITHOUT ANY 12 : WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 : for more details. 15 : 16 : You should have received a copy of the GNU General Public License 17 : along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 : 19 : #ifdef HAVE_CONFIG_H 20 : #include <config.h> 21 : #endif 22 : 23 : #include <stdlib.h> 24 : 25 : #ifdef HAVE_MMAP 26 : 27 : #include <sys/types.h> 28 : #include <sys/mman.h> 29 : 30 : /* The Net-2 man pages says that a MAP_FILE flag is required. */ 31 : #ifndef MAP_FILE 32 : #define MAP_FILE 0 33 : #endif 34 : 35 : #ifdef __cplusplus 36 : extern "C" { 37 : #endif 38 : 39 : /* Prototypes */ 40 : char *mapread(int, int); 41 : int unmap(char *, int); 42 : 43 0 : char *mapread(int fd, int nbytes) 44 : { 45 0 : char *p = (char *)mmap((void *)0, (size_t)nbytes, PROT_READ, 46 : MAP_FILE|MAP_PRIVATE, fd, (off_t)0); 47 0 : if (p == MAP_FAILED) 48 0 : return 0; 49 : /* mmap() shouldn't return 0 since MAP_FIXED wasn't specified. */ 50 0 : if (p == 0) 51 0 : abort(); 52 0 : return p; 53 : } 54 : 55 0 : int unmap(char *p, int len) 56 : { 57 0 : return munmap((void *)p, len); 58 : } 59 : 60 : #ifdef __cplusplus 61 : } 62 : #endif 63 : 64 : #else /* not HAVE_MMAP */ 65 : 66 : #include <errno.h> 67 : 68 : #ifdef __cplusplus 69 : extern "C" { 70 : #endif 71 : 72 : char *mapread(int fd, int nbytes) 73 : { 74 : errno = ENODEV; 75 : return 0; 76 : } 77 : 78 : int unmap(char *p, int len) 79 : { 80 : errno = EINVAL; 81 : return -1; 82 : } 83 : 84 : #ifdef __cplusplus 85 : } 86 : #endif 87 : 88 : #endif /* not HAVE_MMAP */ 89 : 90 : // Local Variables: 91 : // fill-column: 72 92 : // mode: C++ 93 : // End: 94 : // vim: set cindent noexpandtab shiftwidth=2 textwidth=72: