From 8a7bc5f55c025d3d1a49cbee3b56519394abc053 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 7 Sep 2007 13:05:00 +0200 Subject: [PATCH] MinGW: Add a custom implementation for utime(). There seems to be a problem with Microsoft's utime() implementation. With this implementation we ensure that the files times written are UTC. Signed-off-by: Johannes Sixt --- test-chmtime.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test-chmtime.c b/test-chmtime.c index 90da448ebe..b6dc548a2a 100644 --- a/test-chmtime.c +++ b/test-chmtime.c @@ -3,6 +3,38 @@ static const char usage_str[] = "(+|=|=+|=-|-) ..."; +#ifdef __MINGW32__ +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 git_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(_get_osfhandle(fh), NULL, &aft, &mft)) { + errno = EINVAL; + rc = -1; + } else + rc = 0; + close(fh); + return rc; +} + +int git_utime(const char *file_name, const struct utimbuf *times); +#define utime git_utime +#endif /* __MINGW32__ */ + int main(int argc, const char *argv[]) { int i;