X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=common%2Ffile.c;h=a23f0e69416d1c5e0922d2af9d55560162fbc204;hb=41b82fa1b8fbad44a1cc7671bd614b016b2c38b8;hp=dd6fc9157d10fe4117c6dab3490351a73c43d5a9;hpb=193694fdba386a89b4b2a83ce803764302995e89;p=apps%2Fpfixtools.git diff --git a/common/file.c b/common/file.c index dd6fc91..a23f0e6 100644 --- a/common/file.c +++ b/common/file.c @@ -58,7 +58,6 @@ void file_map_delete(file_map_t **map) bool file_map_open(file_map_t *map, const char *file, bool memlock) { - struct stat st; int fd; fd = open(file, O_RDONLY, 0000); @@ -67,13 +66,13 @@ bool file_map_open(file_map_t *map, const char *file, bool memlock) return false; } - if (fstat(fd, &st) < 0) { + if (fstat(fd, &map->st) < 0) { UNIXERR("fstat"); close(fd); return false; } - map->map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + map->map = mmap(NULL, map->st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (map->map == MAP_FAILED) { UNIXERR("mmap"); close(fd); @@ -82,8 +81,8 @@ bool file_map_open(file_map_t *map, const char *file, bool memlock) } close(fd); - map->end = map->map + st.st_size; - map->locked = memlock && mlock(map->map, st.st_size) == 0; + map->end = map->map + map->st.st_size; + map->locked = memlock && mlock(map->map, map->st.st_size) == 0; return true; }