aboutsummaryrefslogtreecommitdiffstats
path: root/util/folder/lstat_win.c
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2022-12-20 00:50:48 +0300
committeralexv-smirnov <alex@ydb.tech>2022-12-20 00:50:48 +0300
commit84f2cfa253cc618438ed6e9d68b33fa7c0d88cb9 (patch)
treef0cf2236e0aafb3e437199f1ac7b559e7fad554a /util/folder/lstat_win.c
parentbde6febc1ad3b826e72746de21d7250803e8e0b5 (diff)
downloadydb-84f2cfa253cc618438ed6e9d68b33fa7c0d88cb9.tar.gz
add windows platform to ydb github export
Diffstat (limited to 'util/folder/lstat_win.c')
-rw-r--r--util/folder/lstat_win.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/util/folder/lstat_win.c b/util/folder/lstat_win.c
new file mode 100644
index 0000000000..cf94cec01a
--- /dev/null
+++ b/util/folder/lstat_win.c
@@ -0,0 +1,35 @@
+#include <util/system/defaults.h>
+
+#ifdef _win_
+ #include <util/system/winint.h>
+ #include "lstat_win.h"
+
+int lstat(const char* fileName, stat_struct* fileStat) {
+ int len = strlen(fileName);
+ int convRes = MultiByteToWideChar(CP_UTF8, 0, fileName, len, 0, 0);
+ if (convRes == 0) {
+ return -1;
+ }
+ WCHAR* buf = malloc(sizeof(WCHAR) * (convRes + 1));
+ MultiByteToWideChar(CP_UTF8, 0, fileName, len, buf, convRes);
+ buf[convRes] = 0;
+
+ HANDLE findHandle;
+ WIN32_FIND_DATAW findBuf;
+ int result;
+ result = _wstat64(buf, fileStat);
+ if (result == 0) {
+ SetLastError(0);
+ findHandle = FindFirstFileW(buf, &findBuf);
+ if (findBuf.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT &&
+ (findBuf.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT || findBuf.dwReserved0 == IO_REPARSE_TAG_SYMLINK))
+ {
+ fileStat->st_mode = fileStat->st_mode & ~_S_IFMT | _S_IFLNK;
+ }
+ FindClose(findHandle);
+ }
+ free(buf);
+ return result;
+}
+
+#endif //_win_