nuclear@2: #include nuclear@2: #include nuclear@2: #include nuclear@2: #include "memmap.h" nuclear@2: nuclear@2: #if defined(__unix__) || defined(__APPLE__) nuclear@2: #include nuclear@2: #include nuclear@2: #include nuclear@2: #include nuclear@2: nuclear@2: int map_file(struct mmfile *mm, const char *fname) nuclear@2: { nuclear@2: int fd; nuclear@2: struct stat st; nuclear@2: nuclear@2: if((fd = open(fname, O_RDONLY)) == -1) { nuclear@2: fprintf(stderr, "map_file: failed to open %s: %s\n", fname, strerror(errno)); nuclear@2: return -1; nuclear@2: } nuclear@2: fstat(fd, &st); nuclear@2: nuclear@2: if((mm->ptr = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == (void*)-1) { nuclear@2: close(fd); nuclear@2: fprintf(stderr, "map_file: failed to map file %s: %s\n", fname, strerror(errno)); nuclear@2: return -1; nuclear@2: } nuclear@2: mm->size = st.st_size; nuclear@2: nuclear@2: close(fd); nuclear@2: return 0; nuclear@2: } nuclear@2: nuclear@2: void unmap_file(struct mmfile *mm) nuclear@2: { nuclear@2: munmap(mm->ptr, mm->size); nuclear@2: } nuclear@2: nuclear@2: #else nuclear@2: /* implement on win32 */ nuclear@2: #endif