]> sourceware.org Git - glibc.git/blob - db2/os/os_map.c
Update.
[glibc.git] / db2 / os / os_map.c
1 /*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
6 */
7
8 #include "config.h"
9
10 #ifndef lint
11 static const char sccsid[] = "@(#)os_map.c 10.7 (Sleepycat) 10/25/97";
12 #endif /* not lint */
13
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
16 #include <sys/mman.h>
17
18 #include <errno.h>
19 #endif
20
21 #include "db_int.h"
22
23 /*
24 * __os_map --
25 * Map in some shared memory backed by a file descriptor.
26 *
27 * PUBLIC: int __os_map __P((int, size_t, int, int, void **));
28 */
29 int
30 __os_map(fd, len, is_private, is_rdonly, addr)
31 int fd, is_private, is_rdonly;
32 size_t len;
33 void **addr;
34 {
35 void *p;
36 int flags, prot;
37
38 flags = is_private ? MAP_PRIVATE : MAP_SHARED;
39 #ifdef MAP_HASSEMAPHORE
40 flags |= MAP_HASSEMAPHORE;
41 #endif
42 prot = PROT_READ | (is_rdonly ? 0 : PROT_WRITE);
43
44 #ifndef MAP_FAILED /* XXX: Mmap(2) failure return. */
45 #define MAP_FAILED -1
46 #endif
47 if ((p =
48 mmap(NULL, len, prot, flags, fd, (off_t)0)) == (void *)MAP_FAILED)
49 return (errno);
50
51 *addr = p;
52 return (0);
53 }
54
55 /*
56 * __os_unmap --
57 * Release the specified shared memory.
58 *
59 * PUBLIC: int __os_unmap __P((void *, size_t));
60 */
61 int
62 __os_unmap(addr, len)
63 void *addr;
64 size_t len;
65 {
66 /*
67 * !!!
68 * The argument len is always the same length as was mapped.
69 */
70 return (munmap(addr, len) ? errno : 0);
71 }
This page took 0.039187 seconds and 5 git commands to generate.