Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 94de0f180e
Fetching contributors…

Cannot retrieve contributors at this time

34 lines (23 sloc) 0.579 kb
#include <string.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include "mmap.h"
void *mmap (void *addr, size_t len, int prot, int flags, int fd, long long offset) {
void *buf;
ssize_t count;
if ( addr || fd == -1 || (prot & PROT_WRITE)) return MAP_FAILED;
buf = malloc(len);
if ( NULL == buf ) return MAP_FAILED;
if (lseek(fd,offset,SEEK_SET) != offset) return MAP_FAILED;
count = read(fd, buf, len);
if (count != len) {
free (buf);
return MAP_FAILED;
}
return buf;
}
int munmap (void *addr, size_t len) {
free (addr);
return 0;
}
Jump to Line
Something went wrong with that request. Please try again.