Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/win32
diff options
context:
space:
mode:
Diffstat (limited to 'src/win32')
-rw-r--r--src/win32/posix.h3
-rw-r--r--src/win32/posix_w32.c38
-rw-r--r--src/win32/w32_util.h10
3 files changed, 51 insertions, 0 deletions
diff --git a/src/win32/posix.h b/src/win32/posix.h
index bf35c8125..ac98fd864 100644
--- a/src/win32/posix.h
+++ b/src/win32/posix.h
@@ -20,6 +20,9 @@ typedef SOCKET GIT_SOCKET;
extern int p_lstat(const char *file_name, struct stat *buf);
extern int p_stat(const char* path, struct stat* buf);
+extern int p_utimes(const char *filename, const struct timeval times[2]);
+extern int p_futimes(int fd, const struct timeval times[2]);
+
extern int p_readlink(const char *path, char *buf, size_t bufsiz);
extern int p_symlink(const char *old, const char *new);
extern int p_link(const char *old, const char *new);
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 332ea233c..504562b0e 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -201,6 +201,44 @@ int p_lstat_posixly(const char *filename, struct stat *buf)
return do_lstat(filename, buf, true);
}
+int p_utimes(const char *filename, const struct timeval times[2])
+{
+ int fd, error;
+
+ if ((fd = p_open(filename, O_RDWR)) < 0)
+ return fd;
+
+ error = p_futimes(fd, times);
+
+ close(fd);
+ return error;
+}
+
+int p_futimes(int fd, const struct timeval times[2])
+{
+ HANDLE handle;
+ FILETIME atime = {0}, mtime = {0};
+
+ if (times == NULL) {
+ SYSTEMTIME st;
+
+ GetSystemTime(&st);
+ SystemTimeToFileTime(&st, &atime);
+ SystemTimeToFileTime(&st, &mtime);
+ } else {
+ git_win32__timeval_to_filetime(&atime, times[0]);
+ git_win32__timeval_to_filetime(&mtime, times[1]);
+ }
+
+ if ((handle = (HANDLE)_get_osfhandle(fd)) == INVALID_HANDLE_VALUE)
+ return -1;
+
+ if (SetFileTime(handle, NULL, &atime, &mtime) == 0)
+ return -1;
+
+ return 0;
+}
+
int p_readlink(const char *path, char *buf, size_t bufsiz)
{
git_win32_path path_w, target_w;
diff --git a/src/win32/w32_util.h b/src/win32/w32_util.h
index 8cb0f5b94..377d651a8 100644
--- a/src/win32/w32_util.h
+++ b/src/win32/w32_util.h
@@ -79,6 +79,16 @@ GIT_INLINE(time_t) git_win32__filetime_to_time_t(const FILETIME *ft)
return (time_t)winTime;
}
+GIT_INLINE(void) git_win32__timeval_to_filetime(
+ FILETIME *ft, const struct timeval tv)
+{
+ long long ticks = (tv.tv_sec * 10000000LL) +
+ (tv.tv_usec * 10LL) + 116444736000000000LL;
+
+ ft->dwHighDateTime = ((ticks >> 32) & 0xffffffffLL);
+ ft->dwLowDateTime = (ticks & 0xffffffffLL);
+}
+
GIT_INLINE(int) git_win32__file_attribute_to_stat(
struct stat *st,
const WIN32_FILE_ATTRIBUTE_DATA *attrdata,