diff options
author | peter <peter@FreeBSD.org> | 1996-11-01 06:45:43 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1996-11-01 06:45:43 +0000 |
commit | 59cc89c2c2e686da3bdab2d5cfac4f33462d29fe (patch) | |
tree | 88f923c9c0be2e2a225a9b21716fd582de668b42 /contrib/nvi/clib/mmap.c | |
download | FreeBSD-src-59cc89c2c2e686da3bdab2d5cfac4f33462d29fe.zip FreeBSD-src-59cc89c2c2e686da3bdab2d5cfac4f33462d29fe.tar.gz |
Import of nvi-1.79, minus a few bits that we dont need (eg: postscript
files, curses, db, regex etc that we already have). The other glue will
follow shortly.
Obtained from: Keith Bostic <bostic@bostic.com>
Diffstat (limited to 'contrib/nvi/clib/mmap.c')
-rw-r--r-- | contrib/nvi/clib/mmap.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/contrib/nvi/clib/mmap.c b/contrib/nvi/clib/mmap.c new file mode 100644 index 0000000..7cea169 --- /dev/null +++ b/contrib/nvi/clib/mmap.c @@ -0,0 +1,50 @@ +#include "config.h" + +#include <sys/types.h> + +#include <stdlib.h> +#include <unistd.h> + +/* + * This function fakes mmap() by reading `len' bytes from the file descriptor + * `fd' and returning a pointer to that memory. The "mapped" region can later + * be deallocated with munmap(). + * + * Note: ONLY reading is supported and only reading of the exact size of the + * file will work. + * + * PUBLIC: #ifndef HAVE_MMAP + * PUBLIC: char *mmap __P((char *, size_t, int, int, int, off_t)); + * PUBLIC: #endif + */ +char * +mmap(addr, len, prot, flags, fd, off) + char *addr; + size_t len; + int prot, flags, fd; + off_t off; +{ + char *ptr; + + if ((ptr = (char *)malloc(len)) == 0) + return ((char *)-1); + if (read(fd, ptr, len) < 0) { + free(ptr); + return ((char *)-1); + } + return (ptr); +} + +/* + * PUBLIC: #ifndef HAVE_MMAP + * PUBLIC: int munmap __P((char *, size_t)); + * PUBLIC: #endif + */ +int +munmap(addr, len) + char *addr; + size_t len; +{ + free(addr); + return (0); +} |