map.c revision 75584
1/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. 2 Written by James Clark (jjc@jclark.com) 3 4This file is part of groff. 5 6groff is free software; you can redistribute it and/or modify it under 7the terms of the GNU General Public License as published by the Free 8Software Foundation; either version 2, or (at your option) any later 9version. 10 11groff is distributed in the hope that it will be useful, but WITHOUT ANY 12WARRANTY; without even the implied warranty of MERCHANTABILITY or 13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14for more details. 15 16You should have received a copy of the GNU General Public License along 17with groff; see the file COPYING. If not, write to the Free Software 18Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 19 20#ifdef HAVE_MMAP 21 22#include <sys/types.h> 23#include <sys/mman.h> 24 25/* The Net-2 man pages says that a MAP_FILE flag is required. */ 26#ifndef MAP_FILE 27#define MAP_FILE 0 28#endif 29 30char *mapread(fd, nbytes) 31 int fd; 32 int nbytes; 33{ 34 char *p = (char *)mmap((caddr_t)0, (size_t)nbytes, PROT_READ, 35 MAP_FILE|MAP_PRIVATE, fd, (off_t)0); 36 if (p == (char *)-1) 37 return 0; 38 /* mmap() shouldn't return 0 since MAP_FIXED wasn't specified. */ 39 if (p == 0) 40 abort(); 41 return p; 42} 43 44int unmap(p, len) 45 char *p; 46 int len; 47{ 48 return munmap((caddr_t)p, len); 49} 50 51#else /* not HAVE_MMAP */ 52 53#include <errno.h> 54 55char *mapread(fd, nbytes) 56 int fd; 57 int nbytes; 58{ 59 errno = ENODEV; 60 return 0; 61} 62 63int unmap(p, len) 64 char *p; 65 int len; 66{ 67 errno = EINVAL; 68 return -1; 69} 70 71#endif /* not HAVE_MMAP */ 72