only call CreateFileMapping if size > 0
This commit is contained in:
parent
100fdd264d
commit
7eb63bc80f
@ -422,7 +422,12 @@ u64 sys_file_size(struct sys_file file)
|
||||
|
||||
struct sys_file_map sys_file_map_open_read(struct sys_file file)
|
||||
{
|
||||
HANDLE map_handle = CreateFileMappingW(
|
||||
u64 size = sys_file_size(file);
|
||||
u8 *base_ptr = NULL;
|
||||
HANDLE map_handle = 0;
|
||||
|
||||
if (size > 0) {
|
||||
map_handle = CreateFileMappingW(
|
||||
(HANDLE)file.handle,
|
||||
NULL,
|
||||
PAGE_READONLY,
|
||||
@ -436,10 +441,6 @@ struct sys_file_map sys_file_map_open_read(struct sys_file file)
|
||||
return (struct sys_file_map) { 0 };
|
||||
}
|
||||
|
||||
u64 size = sys_file_size(file);
|
||||
u8 *base_ptr = NULL;
|
||||
|
||||
if (size > 0) {
|
||||
base_ptr = MapViewOfFile(
|
||||
map_handle,
|
||||
FILE_MAP_READ,
|
||||
@ -456,7 +457,6 @@ struct sys_file_map sys_file_map_open_read(struct sys_file file)
|
||||
}
|
||||
} else {
|
||||
/* File is empty */
|
||||
CloseHandle(map_handle);
|
||||
return (struct sys_file_map) { 0 };
|
||||
}
|
||||
|
||||
@ -468,8 +468,12 @@ struct sys_file_map sys_file_map_open_read(struct sys_file file)
|
||||
|
||||
void sys_file_map_close(struct sys_file_map map)
|
||||
{
|
||||
if (map.mapped_memory.data) {
|
||||
UnmapViewOfFile(map.mapped_memory.data);
|
||||
}
|
||||
if (map.handle) {
|
||||
CloseHandle((HANDLE)map.handle);
|
||||
}
|
||||
}
|
||||
|
||||
struct buffer sys_file_map_data(struct sys_file_map map)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user