You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB
C

24 years ago
#include <sys/types.h>
#include <unistd.h>
#ifdef __MINGW32__
#include <windows.h>
#else
24 years ago
#include <sys/mman.h>
#endif
24 years ago
#include "open.h"
#include "mmap.h"
extern char* mmap_shared(const char* filename,size_t * filesize) {
#ifdef __MINGW32__
HANDLE fd,m;
char* map;
fd=CreateFile(filename,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if (fd==INVALID_HANDLE_VALUE)
return 0;
m=CreateFileMapping(fd,0,PAGE_READWRITE,0,0,NULL);
map=0;
if (m)
if ((map=MapViewOfFile(m,FILE_MAP_WRITE,0,0,0)))
*filesize=GetFileSize(fd,NULL);
CloseHandle(m);
CloseHandle(fd);
return map;
#else
20 years ago
int fd=open_rw(filename);
24 years ago
char *map;
if (fd>=0) {
register off_t o=lseek(fd,0,SEEK_END);
if (sizeof(off_t)!=sizeof(size_t) && o > (off_t)(size_t)-1) { close(fd); return 0; }
*filesize=(size_t)o;
if (o) {
map=mmap(0,*filesize,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
if (map==(char*)-1)
map=0;
} else
map="";
24 years ago
close(fd);
return map;
}
return 0;
#endif
24 years ago
}