summaryrefslogtreecommitdiff
path: root/prism_compile.c
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-09-11 15:09:30 -0400
committerKevin Newton <[email protected]>2024-09-12 13:43:04 -0400
commitca61729fa7713f650c7e4144daa08932f8b66454 ()
tree3da9ba119a11c2905cbf04b6d64b3b9c4a7c0786 /prism_compile.c
parentd4af38ec9d808da3e2f3ba97477332bc96b258b9 (diff)
Fix opening multibyte character filepath on Windows
Notes: Merged: https://.com/ruby/ruby/pull/11497
-rw-r--r--prism_compile.c15
1 files changed, 14 insertions, 1 deletions
@@ -10558,9 +10558,18 @@ read_entire_file(pm_string_t *string, const char *filepath)
{
#ifdef _WIN32
// Open the file for reading.
- HANDLE file = CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
if (file == INVALID_HANDLE_VALUE) {
return false;
}
@@ -10568,6 +10577,7 @@ read_entire_file(pm_string_t *string, const char *filepath)
DWORD file_size = GetFileSize(file, NULL);
if (file_size == INVALID_FILE_SIZE) {
CloseHandle(file);
return false;
}
@@ -10575,6 +10585,7 @@ read_entire_file(pm_string_t *string, const char *filepath)
// the source to a constant empty string and return.
if (file_size == 0) {
CloseHandle(file);
const uint8_t source[] = "";
*string = (pm_string_t) { .type = PM_STRING_CONSTANT, .source = source, .length = 0 };
return true;
@@ -10584,6 +10595,7 @@ read_entire_file(pm_string_t *string, const char *filepath)
HANDLE mapping = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
if (mapping == NULL) {
CloseHandle(file);
return false;
}
@@ -10591,6 +10603,7 @@ read_entire_file(pm_string_t *string, const char *filepath)
uint8_t *source = (uint8_t *) MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
CloseHandle(mapping);
CloseHandle(file);
if (source == NULL) {
return false;