minix/external/bsd/nvi/dist/clib/mmap.c
Lionel Sambuc 84d9c625bf Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC)
- Fix for possible unset uid/gid in toproto
 - Fix for default mtree style
 - Update libelf
 - Importing libexecinfo
 - Resynchronize GCC, mpc, gmp, mpfr
 - build.sh: Replace params with show-params.
     This has been done as the make target has been renamed in the same
     way, while a new target named params has been added. This new
     target generates a file containing all the parameters, instead of
     printing it on the console.
 - Update test48 with new etc/services (Fix by Ben Gras <ben@minix3.org)
     get getservbyport() out of the inner loop

Change-Id: Ie6ad5226fa2621ff9f0dee8782ea48f9443d2091
2014-07-28 17:05:06 +02:00

44 lines
904 B
C

#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(char *addr, size_t len, int prot, int flags, int 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(char *addr, size_t len)
{
free(addr);
return (0);
}