Skip to content

Commit 5b6cfc5

Browse files
committed
Make nob_file_exists() unfailable
1 parent a1fe786 commit 5b6cfc5

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

nob.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,21 +2244,12 @@ NOBDEF bool nob_sv_starts_with(Nob_String_View sv, Nob_String_View expected_pref
22442244
// RETURNS:
22452245
// 0 - file does not exists
22462246
// 1 - file exists
2247-
// -1 - error while checking if file exists. The error is logged
22482247
NOBDEF int nob_file_exists(const char *file_path)
22492248
{
22502249
#if _WIN32
2251-
// TODO: distinguish between "does not exists" and other errors
2252-
DWORD dwAttrib = GetFileAttributesA(file_path);
2253-
return dwAttrib != INVALID_FILE_ATTRIBUTES;
2250+
return GetFileAttributesA(file_path) != INVALID_FILE_ATTRIBUTES;
22542251
#else
2255-
struct stat statbuf;
2256-
if (stat(file_path, &statbuf) < 0) {
2257-
if (errno == ENOENT) return 0;
2258-
nob_log(NOB_ERROR, "Could not check if file %s exists: %s", file_path, strerror(errno));
2259-
return -1;
2260-
}
2261-
return 1;
2252+
return access(file_path, F_OK) == 0;
22622253
#endif
22632254
}
22642255

@@ -2564,6 +2555,7 @@ NOBDEF char *nob_temp_running_executable_path(void)
25642555
- nob_walk_dir()
25652556
- nob_walk_dir_opt()
25662557
Add support for Haiku to nob_temp_running_executable_path() (By @Cephon)
2558+
Make nob_file_exists() unfailable (By @rexim)
25672559
1.27.0 (2025-12-30) Add .dont_reset option to cmd_run (by @Israel77)
25682560
Fix support for FreeBSD (by @cqundefine)
25692561
Strip prefixes from NOB_GO_REBUILD_URSELF and NOB_GO_REBUILD_URSELF_PLUS (by @huwwa)

0 commit comments

Comments
 (0)