Skip to content

Commit f14d6d4

Browse files
committed
chore: use stat instead of fopen
[skip ci]
1 parent 9ac30ad commit f14d6d4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/utils/utils.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,27 @@
88
#include <regex>
99
#include <sstream>
1010

11+
#ifdef _WIN32
12+
#include <windows.h>
13+
#else // POSIX
14+
#include <sys/stat.h>
15+
#endif
16+
1117
namespace duckdb
1218
{
1319
namespace netquack
1420
{
21+
bool file_exists (const char *file_path)
22+
{
23+
#ifdef _WIN32
24+
DWORD attributes = GetFileAttributesA (file_path);
25+
return (attributes != INVALID_FILE_ATTRIBUTES);
26+
#else // POSIX
27+
struct stat buffer;
28+
return (stat (file_path, &buffer) == 0);
29+
#endif
30+
}
31+
1532
CURL *GetCurlHandler ()
1633
{
1734
CURL *curl = curl_easy_init ();
@@ -34,9 +51,8 @@ namespace duckdb
3451
"/etc/ssl/cert.pem" // Alpine Linux
3552
})
3653
{
37-
if (FILE *f = fopen (path, "r"))
54+
if (file_exists (path))
3855
{
39-
fclose (f);
4056
ca_info = path;
4157
break;
4258
}

0 commit comments

Comments
 (0)