diff --git a/mmap.h b/mmap.h index 0681f9b..9f743be 100644 --- a/mmap.h +++ b/mmap.h @@ -4,27 +4,34 @@ #include +#include + #ifdef __cplusplus extern "C" { #endif /* open file for reading, mmap whole file, close file, write length of * map in filesize and return pointer to map. */ +__strin(1) att_write(2) const char* mmap_read(const char *filename,size_t* filesize); /* like mmap_read but use openat instead of open */ +__strin(1) att_write(2) const char* mmap_readat(const char *filename,size_t* filesize,int dirfd); /* open file for reading, mmap whole file privately (copy on write), * close file, write length of map in filesize and return pointer to * map. */ +__strin(1) att_write(2) char* mmap_private(const char *filename,size_t* filesize); /* open file for writing, mmap whole file shared, close file, write * length of map in filesize and return pointer to map. */ +__strin(1) att_write(2) char* mmap_shared(const char *filename,size_t* filesize); /* unmap a mapped region */ +__strin(1) int mmap_unmap(const char* mapped,size_t maplen); #ifdef __cplusplus diff --git a/mmap/mmap_read.c b/mmap/mmap_read.c index 3724b22..2245bb6 100644 --- a/mmap/mmap_read.c +++ b/mmap/mmap_read.c @@ -27,15 +27,15 @@ extern const char* mmap_read(const char* filename,size_t * filesize) { int fd=open_read(filename); char *map; if (fd>=0) { - register off_t o=lseek(fd,0,SEEK_END); + off_t o=lseek(fd,0,SEEK_END); if (o==0 || (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1)) { close(fd); return 0; } *filesize=(size_t)o; if (o>0) { - map=mmap(0,*filesize,PROT_READ,MAP_SHARED,fd,0); + map=(char*)mmap(0,*filesize,PROT_READ,MAP_SHARED,fd,0); if (map==(char*)-1) map=0; } else - map=""; + map=(char*)""; close(fd); return map; }