summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorJohannes Sixt <johannes.sixt@telecom.at>2007-09-07 13:05:00 +0200
committerJohannes Sixt <johannes.sixt@telecom.at>2008-06-26 08:45:11 +0200
commit7c0ffa1cb753f9b909dfb3bc7a5d5417b8de39c2 (patch)
treef073f742b0e75361c365f0ddd6979f5c766809d6 /compat
parent5411bdc4e4b170a57a61b2d486ab344896c41500 (diff)
downloadgit-7c0ffa1cb753f9b909dfb3bc7a5d5417b8de39c2.tar.gz
Windows: Add a custom implementation for utime().
This is a necessary pendant to our lstat implementation: MSVCRT's implementations of lstat and utime do some adjustments if daylight saving time is in effect, but our lstat implementation doesn't do these adjustments and report the correct UTC time. With this implementation we omit the adjustments in utime() as well and always write UTC. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Diffstat (limited to 'compat')
-rw-r--r--compat/mingw.c27
-rw-r--r--compat/mingw.h3
2 files changed, 30 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index 6b742873da..2e47555443 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -155,6 +155,33 @@ int mingw_fstat(int fd, struct stat *buf)
return -1;
}
+static inline void time_t_to_filetime(time_t t, FILETIME *ft)
+{
+ long long winTime = t * 10000000LL + 116444736000000000LL;
+ ft->dwLowDateTime = winTime;
+ ft->dwHighDateTime = winTime >> 32;
+}
+
+int mingw_utime (const char *file_name, const struct utimbuf *times)
+{
+ FILETIME mft, aft;
+ int fh, rc;
+
+ /* must have write permission */
+ if ((fh = open(file_name, O_RDWR | O_BINARY)) < 0)
+ return -1;
+
+ time_t_to_filetime(times->modtime, &mft);
+ time_t_to_filetime(times->actime, &aft);
+ if (!SetFileTime((HANDLE)_get_osfhandle(fh), NULL, &aft, &mft)) {
+ errno = EINVAL;
+ rc = -1;
+ } else
+ rc = 0;
+ close(fh);
+ return rc;
+}
+
unsigned int sleep (unsigned int seconds)
{
Sleep(seconds*1000);
diff --git a/compat/mingw.h b/compat/mingw.h
index 69b1dde3ca..92e9273dd5 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -168,6 +168,9 @@ int mingw_fstat(int fd, struct stat *buf);
#define lstat mingw_lstat
#define stat(x,y) mingw_lstat(x,y)
+int mingw_utime(const char *file_name, const struct utimbuf *times);
+#define utime mingw_utime
+
pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env);
void mingw_execvp(const char *cmd, char *const *argv);
#define execvp mingw_execvp