the script used to extract a release
[nvi.git] / clib / mmap.c
blob7cea169650b439f6dfe7578bd94540bc87cf6aed
1 #include "config.h"
3 #include <sys/types.h>
5 #include <stdlib.h>
6 #include <unistd.h>
8 /*
9 * This function fakes mmap() by reading `len' bytes from the file descriptor
10 * `fd' and returning a pointer to that memory. The "mapped" region can later
11 * be deallocated with munmap().
13 * Note: ONLY reading is supported and only reading of the exact size of the
14 * file will work.
16 * PUBLIC: #ifndef HAVE_MMAP
17 * PUBLIC: char *mmap __P((char *, size_t, int, int, int, off_t));
18 * PUBLIC: #endif
20 char *
21 mmap(addr, len, prot, flags, fd, off)
22 char *addr;
23 size_t len;
24 int prot, flags, fd;
25 off_t off;
27 char *ptr;
29 if ((ptr = (char *)malloc(len)) == 0)
30 return ((char *)-1);
31 if (read(fd, ptr, len) < 0) {
32 free(ptr);
33 return ((char *)-1);
35 return (ptr);
39 * PUBLIC: #ifndef HAVE_MMAP
40 * PUBLIC: int munmap __P((char *, size_t));
41 * PUBLIC: #endif
43 int
44 munmap(addr, len)
45 char *addr;
46 size_t len;
48 free(addr);
49 return (0);