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