1151497Sru/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2004 2104862Sru Free Software Foundation, Inc. 375584Sru Written by James Clark (jjc@jclark.com) 475584Sru 575584SruThis file is part of groff. 675584Sru 775584Srugroff is free software; you can redistribute it and/or modify it under 875584Sruthe terms of the GNU General Public License as published by the Free 975584SruSoftware Foundation; either version 2, or (at your option) any later 1075584Sruversion. 1175584Sru 1275584Srugroff is distributed in the hope that it will be useful, but WITHOUT ANY 1375584SruWARRANTY; without even the implied warranty of MERCHANTABILITY or 1475584SruFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1575584Srufor more details. 1675584Sru 1775584SruYou should have received a copy of the GNU General Public License along 1875584Sruwith groff; see the file COPYING. If not, write to the Free Software 19151497SruFoundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */ 2075584Sru 21104862Sru#include <stdlib.h> 22104862Sru 23104862Sru#ifdef HAVE_CONFIG_H 24104862Sru#include <config.h> 25104862Sru#endif 26104862Sru 2775584Sru#ifdef HAVE_MMAP 2875584Sru 2975584Sru#include <sys/types.h> 3075584Sru#include <sys/mman.h> 3175584Sru 3275584Sru/* The Net-2 man pages says that a MAP_FILE flag is required. */ 3375584Sru#ifndef MAP_FILE 3475584Sru#define MAP_FILE 0 3575584Sru#endif 3675584Sru 37151497Sru#ifdef __cplusplus 38151497Sruextern "C" { 39151497Sru#endif 40151497Sru 41151497Sruchar *mapread(int fd, int nbytes) 4275584Sru{ 43151497Sru char *p = (char *)mmap((void *)0, (size_t)nbytes, PROT_READ, 4475584Sru MAP_FILE|MAP_PRIVATE, fd, (off_t)0); 4575584Sru if (p == (char *)-1) 4675584Sru return 0; 4775584Sru /* mmap() shouldn't return 0 since MAP_FIXED wasn't specified. */ 4875584Sru if (p == 0) 4975584Sru abort(); 5075584Sru return p; 5175584Sru} 5275584Sru 53151497Sruint unmap(char *p, int len) 5475584Sru{ 55151497Sru return munmap((void *)p, len); 5675584Sru} 5775584Sru 58151497Sru#ifdef __cplusplus 59151497Sru} 60151497Sru#endif 61151497Sru 6275584Sru#else /* not HAVE_MMAP */ 6375584Sru 6475584Sru#include <errno.h> 6575584Sru 66151497Sru#ifdef __cplusplus 67151497Sruextern "C" { 68151497Sru#endif 69151497Sru 70151497Sruchar *mapread(int fd, int nbytes) 7175584Sru{ 7275584Sru errno = ENODEV; 7375584Sru return 0; 7475584Sru} 7575584Sru 76151497Sruint unmap(char *p, int len) 7775584Sru{ 7875584Sru errno = EINVAL; 7975584Sru return -1; 8075584Sru} 8175584Sru 82151497Sru#ifdef __cplusplus 83151497Sru} 84151497Sru#endif 85151497Sru 8675584Sru#endif /* not HAVE_MMAP */ 87