From 92d3c7a4cd5ecbf8bb363974352b3eaa907256e5 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Wed, 22 Dec 2021 18:04:36 +0000 Subject: [PATCH] Add realpath() for Win32 --- mongoose.c | 7 ++++++- mongoose.h | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mongoose.c b/mongoose.c index d3624554..15c2ca6e 100644 --- a/mongoose.c +++ b/mongoose.c @@ -517,7 +517,11 @@ struct mg_fs mg_fs_packed = {packed_stat, packed_list, packed_open, #if MG_ENABLE_FILE static int p_stat(const char *path, size_t *size, time_t *mtime) { -#ifdef _WIN32 +#if !defined(S_ISDIR) + LOG(LL_ERROR, ("stat() API is not supported. %p %p %p", path, size, mtime)); + return 0; +#else +#if defined(_WIN32) struct _stati64 st; wchar_t tmp[PATH_MAX]; MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0])); @@ -529,6 +533,7 @@ static int p_stat(const char *path, size_t *size, time_t *mtime) { if (size) *size = (size_t) st.st_size; if (mtime) *mtime = st.st_mtime; return MG_FS_READ | MG_FS_WRITE | (S_ISDIR(st.st_mode) ? MG_FS_DIR : 0); +#endif } #ifdef _WIN32 diff --git a/mongoose.h b/mongoose.h index 447f51d6..221298d9 100644 --- a/mongoose.h +++ b/mongoose.h @@ -387,7 +387,6 @@ typedef enum { false = 0, true = 1 } bool; // Protect from calls like std::snprintf in app code // See https://github.com/cesanta/mongoose/issues/1047 #ifndef __cplusplus -#define sleep(x) Sleep(x) #define snprintf _snprintf #define vsnprintf _vsnprintf #ifndef strdup // For MSVC with _DEBUG, see #1359 @@ -408,6 +407,9 @@ typedef int socklen_t; #define EWOULDBLOCK WSAEWOULDBLOCK #endif +#define realpath(a, b) _fullpath((b), (a), MG_PATH_MAX) +#define sleep(x) Sleep(x) + #ifndef va_copy #ifdef __va_copy #define va_copy __va_copy