summaryrefslogtreecommitdiff
path: root/src/win32/w32_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/win32/w32_util.h')
-rw-r--r--src/win32/w32_util.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/win32/w32_util.h b/src/win32/w32_util.h
index 9c1b94359..8cb0f5b94 100644
--- a/src/win32/w32_util.h
+++ b/src/win32/w32_util.h
@@ -9,8 +9,21 @@
#define INCLUDE_w32_util_h__
#include "utf-conv.h"
+#include "posix.h"
#include "path_w32.h"
+/*
+
+#include "common.h"
+#include "path.h"
+#include "path_w32.h"
+#include "utf-conv.h"
+#include "posix.h"
+#include "reparse.h"
+#include "dir.h"
+*/
+
+
GIT_INLINE(bool) git_win32__isalpha(wchar_t c)
{
return ((c >= L'A' && c <= L'Z') || (c >= L'a' && c <= L'z'));
@@ -52,4 +65,63 @@ size_t git_win32__path_trim_end(wchar_t *str, size_t len);
*/
size_t git_win32__canonicalize_path(wchar_t *str, size_t len);
+/**
+ * Converts a FILETIME structure to a time_t.
+ *
+ * @param FILETIME A pointer to a FILETIME
+ * @return A time_t containing the same time
+ */
+GIT_INLINE(time_t) git_win32__filetime_to_time_t(const FILETIME *ft)
+{
+ long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
+ winTime -= 116444736000000000LL; /* Windows to Unix Epoch conversion */
+ winTime /= 10000000; /* Nano to seconds resolution */
+ return (time_t)winTime;
+}
+
+GIT_INLINE(int) git_win32__file_attribute_to_stat(
+ struct stat *st,
+ const WIN32_FILE_ATTRIBUTE_DATA *attrdata,
+ const wchar_t *path)
+{
+ mode_t mode = S_IREAD;
+
+ if (attrdata->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ mode |= S_IFDIR;
+ else
+ mode |= S_IFREG;
+
+ if ((attrdata->dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0)
+ mode |= S_IWRITE;
+
+ st->st_ino = 0;
+ st->st_gid = 0;
+ st->st_uid = 0;
+ st->st_nlink = 1;
+ st->st_mode = mode;
+ st->st_size = ((git_off_t)attrdata->nFileSizeHigh << 32) + attrdata->nFileSizeLow;
+ st->st_dev = _getdrive() - 1;
+ st->st_rdev = st->st_dev;
+ st->st_atime = git_win32__filetime_to_time_t(&(attrdata->ftLastAccessTime));
+ st->st_mtime = git_win32__filetime_to_time_t(&(attrdata->ftLastWriteTime));
+ st->st_ctime = git_win32__filetime_to_time_t(&(attrdata->ftCreationTime));
+
+ if (attrdata->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && path) {
+ git_win32_path target;
+
+ if (git_win32_path_readlink_w(target, path) >= 0) {
+ st->st_mode = (st->st_mode & ~S_IFMT) | S_IFLNK;
+
+ /* st_size gets the UTF-8 length of the target name, in bytes,
+ * not counting the NULL terminator */
+ if ((st->st_size = git__utf16_to_8(NULL, 0, target)) < 0) {
+ giterr_set(GITERR_OS, "Could not convert reparse point name for '%s'", path);
+ return -1;
+ }
+ }
+ }
+
+ return 0;
+}
+
#endif