Skip to content

Commit 0974ba1

Browse files
committed
nob_file_exists
1 parent e2416ed commit 0974ba1

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
@@ -2960,10 +2960,18 @@ NOBDEF bool nob_sv_starts_with(Nob_String_View sv, Nob_String_View expected_pref
29602960
NOBDEF int nob_file_exists(const char *file_path)
29612961
{
29622962
#if _WIN32
2963-
return GetFileAttributesA(file_path) != INVALID_FILE_ATTRIBUTES;
2963+
size_t mark;
2964+
wchar_t *wide_file_path;
2965+
bool ret;
2966+
2967+
mark = nob_temp_save();
2968+
wide_file_path = nob__unicode_utf8_to_unicode_utf16_temp(file_path);
2969+
ret = GetFileAttributesW(wide_file_path) != INVALID_FILE_ATTRIBUTES;
2970+
nob_temp_rewind(mark);
2971+
return ret;
29642972
#else
29652973
return access(file_path, F_OK) == 0;
2966-
#endif
2974+
#endif // _WIN32
29672975
}
29682976

29692977
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)