only call CreateFileMapping if size > 0
This commit is contained in:
parent
100fdd264d
commit
7eb63bc80f
@ -422,24 +422,25 @@ 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(
|
|
||||||
(HANDLE)file.handle,
|
|
||||||
NULL,
|
|
||||||
PAGE_READONLY,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!map_handle) {
|
|
||||||
ASSERT(false);
|
|
||||||
return (struct sys_file_map) { 0 };
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 size = sys_file_size(file);
|
u64 size = sys_file_size(file);
|
||||||
u8 *base_ptr = NULL;
|
u8 *base_ptr = NULL;
|
||||||
|
HANDLE map_handle = 0;
|
||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
|
map_handle = CreateFileMappingW(
|
||||||
|
(HANDLE)file.handle,
|
||||||
|
NULL,
|
||||||
|
PAGE_READONLY,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!map_handle) {
|
||||||
|
ASSERT(false);
|
||||||
|
return (struct sys_file_map) { 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,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)
|
void sys_file_map_close(struct sys_file_map map)
|
||||||
{
|
{
|
||||||
UnmapViewOfFile(map.mapped_memory.data);
|
if (map.mapped_memory.data) {
|
||||||
CloseHandle((HANDLE)map.handle);
|
UnmapViewOfFile(map.mapped_memory.data);
|
||||||
|
}
|
||||||
|
if (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