@matheusbsbs / matheus-bagliano / commits / 7c0ffa1cb7
Fork 0

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>

Johannes Sixt committed Sep 7, 2007 at 13:05 UTC 7c0ffa1cb753f9b909dfb3bc7a5d5417b8de39c2
2 files changed +30
compat/mingw.c
+27
@@ -155,6 +155,33 @@ int mingw_fstat(int fd, struct stat *buf)
155 return -1;
156 }
157
158 +static inline void time_t_to_filetime(time_t t, FILETIME *ft)
159 +{
160 + long long winTime = t * 10000000LL + 116444736000000000LL;
161 + ft->dwLowDateTime = winTime;
162 + ft->dwHighDateTime = winTime >> 32;
163 +}
164 +
165 +int mingw_utime (const char *file_name, const struct utimbuf *times)
166 +{
167 + FILETIME mft, aft;
168 + int fh, rc;
169 +
170 + /* must have write permission */
171 + if ((fh = open(file_name, O_RDWR | O_BINARY)) < 0)
172 + return -1;
173 +
174 + time_t_to_filetime(times->modtime, &mft);
175 + time_t_to_filetime(times->actime, &aft);
176 + if (!SetFileTime((HANDLE)_get_osfhandle(fh), NULL, &aft, &mft)) {
177 + errno = EINVAL;
178 + rc = -1;
179 + } else
180 + rc = 0;
181 + close(fh);
182 + return rc;
183 +}
184 +
185 unsigned int sleep (unsigned int seconds)
186 {
187 Sleep(seconds*1000);
compat/mingw.h
+3
@@ -168,6 +168,9 @@ int mingw_fstat(int fd, struct stat *buf);
168 #define lstat mingw_lstat
169 #define stat(x,y) mingw_lstat(x,y)
170
171 +int mingw_utime(const char *file_name, const struct utimbuf *times);
172 +#define utime mingw_utime
173 +
174 pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env);
175 void mingw_execvp(const char *cmd, char *const *argv);
176 #define execvp mingw_execvp