Skip to content

Commit 7426153

Browse files
committed
nob_file_exists
1 parent 0814922 commit 7426153

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

nob.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,10 +2607,18 @@ NOBDEF bool nob_sv_starts_with(Nob_String_View sv, Nob_String_View expected_pref
26072607
NOBDEF int nob_file_exists(const char *file_path)
26082608
{
26092609
#if _WIN32
2610-
return GetFileAttributesA(file_path) != INVALID_FILE_ATTRIBUTES;
2610+
size_t mark;
2611+
wchar_t *wide_file_path;
2612+
bool ret;
2613+
2614+
mark = nob_temp_save();
2615+
wide_file_path = nob__unicode_utf8_to_unicode_utf16_temp(file_path);
2616+
ret = GetFileAttributesW(wide_file_path) != INVALID_FILE_ATTRIBUTES;
2617+
nob_temp_rewind(mark);
2618+
return ret;
26112619
#else
26122620
return access(file_path, F_OK) == 0;
2613-
#endif
2621+
#endif // _WIN32
26142622
}
26152623

26162624
NOBDEF const char *nob_get_current_dir_temp(void)

tests/unicode.c

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

105+
b = nob_file_exists(k_strings[i]);
106+
test(b);
107+
105108
b = nob_delete_file(k_strings[i]);
106109
test(b);
110+
111+
b = nob_file_exists(k_strings[i]);
112+
test(!b);
107113
}
108114
}
109115

0 commit comments

Comments
 (0)