summaryrefslogtreecommitdiff
path: root/src/fs_win32.h
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2023-02-15 19:32:37 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2023-05-03 23:11:34 -0400
commit05b3d156c31af25bc08a6a7117899e39e337b48f (patch)
treed977efa7a2d7be78eb03f1972bf1fcee779809e0 /src/fs_win32.h
parent3f4e686cdcb2932057b4108c702bbb4aa4018846 (diff)
downloadlighttpd-git-05b3d156c31af25bc08a6a7117899e39e337b48f.tar.gz
[core] _WIN32 custom fs funcs on UTF-8 paths
open(), stat(), mkdir() on UTF-8 paths lighttpd provides large file support and 64-bit time, so provide override to use _stati64() (and _wstati64()) Additionally, provide custom function to support stat on UTF-8 path, which must first be converted to wide-char and _wstati64(), since _stati64() is naive and does not properly support UTF-8.
Diffstat (limited to 'src/fs_win32.h')
-rw-r--r--src/fs_win32.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/fs_win32.h b/src/fs_win32.h
new file mode 100644
index 00000000..0b1af742
--- /dev/null
+++ b/src/fs_win32.h
@@ -0,0 +1,70 @@
+/*
+ * fs_win32 - filesystem _WIN32 API wrapper
+ *
+ * Copyright(c) 2023 Glenn Strauss gstrauss()gluelogic.com All rights reserved
+ * License: BSD 3-clause (same as lighttpd)
+ */
+#ifndef INCLUDED_FS_WIN32_H
+#define INCLUDED_FS_WIN32_H
+#include "first.h"
+
+#ifdef _WIN32
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+/* MS filesystem API does not support UTF-8? WTH? write our own; not hard */
+
+int fs_win32_openUTF8 (const char *path, int oflag, int pmode);
+
+#include <direct.h>
+#undef mkdir
+#define mkdir(a,b) fs_win32_mkdirUTF8((a),(b))
+int fs_win32_mkdirUTF8 (const char *path, mode_t mode);
+
+#undef stat
+#undef fstat
+#define stat fs_win32_stati64UTF8
+#define fstat(fd,st) _fstati64((fd),(struct _stati64 *)(st))
+
+/*('#define stat fs_win32_stati64UTF8' must handle 'struct stat' definitions)*/
+struct fs_win32_stati64UTF8 {
+#if 1 /*(?non-standard?) (appears to work)*/
+ struct _stati64; /*(intentionally unnamed for transparent struct)*/
+#else
+/* /usr/x86_64-w64-mingw32/sys-root/mingw/include/_mingw_stat64.h */
+ #ifdef __MINGW_EXTENSION
+ _dev_t st_dev;
+ _ino_t st_ino;
+ unsigned short st_mode;
+ short st_nlink;
+ short st_uid;
+ short st_gid;
+ _dev_t st_rdev;
+ __MINGW_EXTENSION __int64 st_size;
+ __time64_t st_atime;
+ __time64_t st_mtime;
+ __time64_t st_ctime;
+ #else
+/* C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt/sys/stat.h*/
+ _dev_t st_dev;
+ _ino_t st_ino;
+ unsigned short st_mode;
+ short st_nlink;
+ short st_uid;
+ short st_gid;
+ _dev_t st_rdev;
+ __int64 st_size;
+ __time64_t st_atime;
+ __time64_t st_mtime;
+ __time64_t st_ctime;
+ #endif
+#endif
+};
+
+/* could be inline compat func here, but fairly large func */
+int fs_win32_stati64UTF8 (const char *path, struct fs_win32_stati64UTF8 *st);
+
+#endif /* _WIN32 */
+
+#endif