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-04-20 19:14:14 +0200
commit28d6ffcd5e47bc4e648b70c917eeda25f6798f89 (patch)
treed32cdc1714aa68707d84723cc1863858897b0e4a /win32
parentd93380efb2a443a1cb7997c85c9a512ddb408632 (diff)
downloadbusybox-w32-28d6ffcd5e47bc4e648b70c917eeda25f6798f89.tar.gz
busybox-w32-28d6ffcd5e47bc4e648b70c917eeda25f6798f89.tar.bz2
busybox-w32-28d6ffcd5e47bc4e648b70c917eeda25f6798f89.zip
win32: add utime()
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
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 51011eb88..dda7d654f 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);