fix shared and private mmapping (Unix and Windoze)

master
leitner 20 years ago
parent 60f3320ae0
commit 43493f0c56

@ -12,7 +12,7 @@ char* mmap_private(const char* filename,unsigned long* filesize) {
#ifdef __MINGW32__ #ifdef __MINGW32__
HANDLE fd,m; HANDLE fd,m;
char* map; char* map;
fd=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); fd=CreateFile(filename,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if (fd==INVALID_HANDLE_VALUE) if (fd==INVALID_HANDLE_VALUE)
return 0; return 0;
m=CreateFileMapping(fd,0,PAGE_WRITECOPY,0,0,NULL); m=CreateFileMapping(fd,0,PAGE_WRITECOPY,0,0,NULL);
@ -27,7 +27,7 @@ char* mmap_private(const char* filename,unsigned long* filesize) {
char *map; char *map;
if (fd>=0) { if (fd>=0) {
*filesize=lseek(fd,0,SEEK_END); *filesize=lseek(fd,0,SEEK_END);
map=mmap(0,*filesize,PROT_WRITE,MAP_PRIVATE,fd,0); map=mmap(0,*filesize,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0);
if (map==(char*)-1) if (map==(char*)-1)
map=0; map=0;
close(fd); close(fd);

@ -12,7 +12,7 @@ extern char* mmap_shared(const char* filename,unsigned long* filesize) {
#ifdef __MINGW32__ #ifdef __MINGW32__
HANDLE fd,m; HANDLE fd,m;
char* map; char* map;
fd=CreateFile(filename,GENERIC_WRITE,FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); fd=CreateFile(filename,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if (fd==INVALID_HANDLE_VALUE) if (fd==INVALID_HANDLE_VALUE)
return 0; return 0;
m=CreateFileMapping(fd,0,PAGE_READWRITE,0,0,NULL); m=CreateFileMapping(fd,0,PAGE_READWRITE,0,0,NULL);
@ -27,7 +27,7 @@ extern char* mmap_shared(const char* filename,unsigned long* filesize) {
char *map; char *map;
if (fd>=0) { if (fd>=0) {
*filesize=lseek(fd,0,SEEK_END); *filesize=lseek(fd,0,SEEK_END);
map=mmap(0,*filesize,PROT_WRITE,MAP_SHARED,fd,0); map=mmap(0,*filesize,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
if (map==(char*)-1) if (map==(char*)-1)
map=0; map=0;
close(fd); close(fd);

Loading…
Cancel
Save