aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-04-14 06:54:25 +0200
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-09-10 19:28:26 +1000
commit37b6f2e7d0664e9453e78df9ba05db8712a8b088 (patch)
tree1958063b8cd6e09a3ff7a3a930232ba72cb094ed /win32
parent0e9b2733fa46bb92178a832d85c0773ce16814af (diff)
downloadbusybox-w32-37b6f2e7d0664e9453e78df9ba05db8712a8b088.tar.gz
busybox-w32-37b6f2e7d0664e9453e78df9ba05db8712a8b088.tar.bz2
busybox-w32-37b6f2e7d0664e9453e78df9ba05db8712a8b088.zip
win32: add utime()
Diffstat (limited to 'win32')
-rw-r--r--win32/mingw.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index e4ff14357..0fcaeb313 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -290,6 +290,35 @@ int mingw_fstat(int fd, struct stat *buf)
290 return -1; 290 return -1;
291} 291}
292 292
293static inline void time_t_to_filetime(time_t t, FILETIME *ft)
294{
295 long long winTime = t * 10000000LL + 116444736000000000LL;
296 ft->dwLowDateTime = winTime;
297 ft->dwHighDateTime = winTime >> 32;
298}
299
300int mingw_utime (const char *file_name, const struct utimbuf *times)
301{
302 FILETIME mft, aft;
303 int fh, rc;
304
305 /* must have write permission */
306 if ((fh = open(file_name, O_RDWR | O_BINARY)) < 0)
307 return -1;
308
309 if (times) {
310 time_t_to_filetime(times->modtime, &mft);
311 time_t_to_filetime(times->actime, &aft);
312 }
313 if (!SetFileTime((HANDLE)_get_osfhandle(fh), NULL, &aft, &mft)) {
314 errno = EINVAL;
315 rc = -1;
316 } else
317 rc = 0;
318 close(fh);
319 return rc;
320}
321
293unsigned int sleep (unsigned int seconds) 322unsigned int sleep (unsigned int seconds)
294{ 323{
295 Sleep(seconds*1000); 324 Sleep(seconds*1000);