xref: /netbsd/external/gpl2/groff/dist/src/libs/libbib/map.c (revision 04ac863b)
1*04ac863bSchristos /*	$NetBSD: map.c,v 1.1.1.1 2016/01/13 18:41:48 christos Exp $	*/
2*04ac863bSchristos 
3*04ac863bSchristos /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2004
4*04ac863bSchristos    Free Software Foundation, Inc.
5*04ac863bSchristos      Written by James Clark (jjc@jclark.com)
6*04ac863bSchristos 
7*04ac863bSchristos This file is part of groff.
8*04ac863bSchristos 
9*04ac863bSchristos groff is free software; you can redistribute it and/or modify it under
10*04ac863bSchristos the terms of the GNU General Public License as published by the Free
11*04ac863bSchristos Software Foundation; either version 2, or (at your option) any later
12*04ac863bSchristos version.
13*04ac863bSchristos 
14*04ac863bSchristos groff is distributed in the hope that it will be useful, but WITHOUT ANY
15*04ac863bSchristos WARRANTY; without even the implied warranty of MERCHANTABILITY or
16*04ac863bSchristos FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17*04ac863bSchristos for more details.
18*04ac863bSchristos 
19*04ac863bSchristos You should have received a copy of the GNU General Public License along
20*04ac863bSchristos with groff; see the file COPYING.  If not, write to the Free Software
21*04ac863bSchristos Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
22*04ac863bSchristos 
23*04ac863bSchristos #include <stdlib.h>
24*04ac863bSchristos 
25*04ac863bSchristos #ifdef HAVE_CONFIG_H
26*04ac863bSchristos #include <config.h>
27*04ac863bSchristos #endif
28*04ac863bSchristos 
29*04ac863bSchristos #ifdef HAVE_MMAP
30*04ac863bSchristos 
31*04ac863bSchristos #include <sys/types.h>
32*04ac863bSchristos #include <sys/mman.h>
33*04ac863bSchristos 
34*04ac863bSchristos /* The Net-2 man pages says that a MAP_FILE flag is required. */
35*04ac863bSchristos #ifndef MAP_FILE
36*04ac863bSchristos #define MAP_FILE 0
37*04ac863bSchristos #endif
38*04ac863bSchristos 
39*04ac863bSchristos #ifdef __cplusplus
40*04ac863bSchristos extern "C" {
41*04ac863bSchristos #endif
42*04ac863bSchristos 
mapread(int fd,int nbytes)43*04ac863bSchristos char *mapread(int fd, int nbytes)
44*04ac863bSchristos {
45*04ac863bSchristos   char *p = (char *)mmap((void *)0, (size_t)nbytes, PROT_READ,
46*04ac863bSchristos 			 MAP_FILE|MAP_PRIVATE, fd, (off_t)0);
47*04ac863bSchristos   if (p == (char *)-1)
48*04ac863bSchristos     return 0;
49*04ac863bSchristos   /* mmap() shouldn't return 0 since MAP_FIXED wasn't specified. */
50*04ac863bSchristos   if (p == 0)
51*04ac863bSchristos     abort();
52*04ac863bSchristos   return p;
53*04ac863bSchristos }
54*04ac863bSchristos 
unmap(char * p,int len)55*04ac863bSchristos int unmap(char *p, int len)
56*04ac863bSchristos {
57*04ac863bSchristos   return munmap((void *)p, len);
58*04ac863bSchristos }
59*04ac863bSchristos 
60*04ac863bSchristos #ifdef __cplusplus
61*04ac863bSchristos }
62*04ac863bSchristos #endif
63*04ac863bSchristos 
64*04ac863bSchristos #else /* not HAVE_MMAP */
65*04ac863bSchristos 
66*04ac863bSchristos #include <errno.h>
67*04ac863bSchristos 
68*04ac863bSchristos #ifdef __cplusplus
69*04ac863bSchristos extern "C" {
70*04ac863bSchristos #endif
71*04ac863bSchristos 
mapread(int fd,int nbytes)72*04ac863bSchristos char *mapread(int fd, int nbytes)
73*04ac863bSchristos {
74*04ac863bSchristos   errno = ENODEV;
75*04ac863bSchristos   return 0;
76*04ac863bSchristos }
77*04ac863bSchristos 
unmap(char * p,int len)78*04ac863bSchristos int unmap(char *p, int len)
79*04ac863bSchristos {
80*04ac863bSchristos   errno = EINVAL;
81*04ac863bSchristos   return -1;
82*04ac863bSchristos }
83*04ac863bSchristos 
84*04ac863bSchristos #ifdef __cplusplus
85*04ac863bSchristos }
86*04ac863bSchristos #endif
87*04ac863bSchristos 
88*04ac863bSchristos #endif /* not HAVE_MMAP */
89