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)
|
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,
|
(HANDLE)file.handle,
|
||||||
NULL,
|
NULL,
|
||||||
PAGE_READONLY,
|
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 };
|
return (struct sys_file_map) { 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 size = sys_file_size(file);
|
|
||||||
u8 *base_ptr = NULL;
|
|
||||||
|
|
||||||
if (size > 0) {
|
|
||||||
base_ptr = MapViewOfFile(
|
base_ptr = MapViewOfFile(
|
||||||
map_handle,
|
map_handle,
|
||||||
FILE_MAP_READ,
|
FILE_MAP_READ,
|
||||||
@ -456,7 +457,6 @@ struct sys_file_map sys_file_map_open_read(struct sys_file file)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* File is empty */
|
/* File is empty */
|
||||||
CloseHandle(map_handle);
|
|
||||||
return (struct sys_file_map) { 0 };
|
return (struct sys_file_map) { 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,9 +468,13 @@ struct sys_file_map sys_file_map_open_read(struct sys_file file)
|
|||||||
|
|
||||||
void sys_file_map_close(struct sys_file_map map)
|
void sys_file_map_close(struct sys_file_map map)
|
||||||
{
|
{
|
||||||
|
if (map.mapped_memory.data) {
|
||||||
UnmapViewOfFile(map.mapped_memory.data);
|
UnmapViewOfFile(map.mapped_memory.data);
|
||||||
|
}
|
||||||
|
if (map.handle) {
|
||||||
CloseHandle((HANDLE)map.handle);
|
CloseHandle((HANDLE)map.handle);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct buffer sys_file_map_data(struct sys_file_map map)
|
struct buffer sys_file_map_data(struct sys_file_map map)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user