Skip to content

Commit 0db3cc9

Browse files
committed
Moar Windows UNICODE stuff. nob_file_exists
1 parent 33e28b4 commit 0db3cc9

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

nob.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2645,7 +2645,15 @@ NOBDEF bool nob_sv_starts_with(Nob_String_View sv, Nob_String_View expected_pref
26452645
NOBDEF int nob_file_exists(const char *file_path)
26462646
{
26472647
#if _WIN32
2648-
return GetFileAttributesA(file_path) != INVALID_FILE_ATTRIBUTES;
2648+
size_t mark;
2649+
wchar_t* wide_file_path;
2650+
bool ret;
2651+
2652+
mark = nob_temp_save();
2653+
wide_file_path = nob_unicode_utf8_to_unicode_utf16(file_path);
2654+
ret = GetFileAttributesW(wide_file_path) != INVALID_FILE_ATTRIBUTES;
2655+
nob_temp_rewind(mark);
2656+
return ret;
26492657
#else
26502658
return access(file_path, F_OK) == 0;
26512659
#endif

tests/unicode.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,14 @@ static void test_unicode_utf8_file_operations(void)
125125
test(memcmp(sb.items, "test", 4) == 0);
126126
NOB_FREE(sb.items);
127127

128+
b = nob_file_exists(k_strings[i]);
129+
test(b);
130+
128131
b = nob_delete_file(k_strings[i]);
129132
test(b);
133+
134+
b = nob_file_exists(k_strings[i]);
135+
test(!b);
130136
}
131137
nob_custom_printf("\n");
132138
}

0 commit comments

Comments
 (0)