ex: convert line input buffer from file encoding to internal encoding
[nvi.git] / clib / mmap.c
blob8f6d6124dc1574e02b137ec3d04c81c37462b4f5
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(char *addr, size_t len, int prot, int flags, int fd, off_t off)
23 char *ptr;
25 if ((ptr = (char *)malloc(len)) == 0)
26 return ((char *)-1);
27 if (read(fd, ptr, len) < 0) {
28 free(ptr);
29 return ((char *)-1);
31 return (ptr);
35 * PUBLIC: #ifndef HAVE_MMAP
36 * PUBLIC: int munmap __P((char *, size_t));
37 * PUBLIC: #endif
39 int
40 munmap(char *addr, size_t len)
42 free(addr);
43 return (0);