From 0bd2cfd0fc40fb4d0b362798aff6a60f0b87af96 Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Mon, 28 Jun 2021 19:33:14 +0200 Subject: [PATCH] Update file_exists() function to work with directories on Windows. And then let's use the similar (and faster) function on Linux too. --- src/misc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/misc.c b/src/misc.c index cffe76827..a3196709c 100644 --- a/src/misc.c +++ b/src/misc.c @@ -2094,17 +2094,16 @@ int filename_has_suffix(const char *fname, const char *suffix) return 0; } -/** Check if the specified file exists */ +/** Check if the specified file or directory exists */ int file_exists(char *file) { - FILE *fd; - - fd = fopen(file, "r"); - if (!fd) - return 0; - - fclose(fd); - return 1; +#ifdef _WIN32 + if (_access(file, 0) == 0) +#else + if (access(file, 0) == 0) +#endif + return 1; + return 0; } /** Get the file creation time */