aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-04-06 17:23:16 +0200
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-09-10 19:28:27 +1000
commitda42856b7970e9221216c88926b626f8efda4f51 (patch)
tree30b51aed71a6e90fa2f488be7f862c0523d9da30
parentf630faee2045fa28c61a3cea760ab8a9b65c1bb3 (diff)
downloadbusybox-w32-da42856b7970e9221216c88926b626f8efda4f51.tar.gz
busybox-w32-da42856b7970e9221216c88926b626f8efda4f51.tar.bz2
busybox-w32-da42856b7970e9221216c88926b626f8efda4f51.zip
win32: add utimes and fix utime(file,NULL)
-rw-r--r--include/mingw.h2
-rw-r--r--win32/mingw.c41
2 files changed, 42 insertions, 1 deletions
diff --git a/include/mingw.h b/include/mingw.h
index c2953c390..5294d9d6c 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -306,7 +306,7 @@ NOIMPL(vfork,void);
306 * utime.h 306 * utime.h
307 */ 307 */
308int mingw_utime(const char *file_name, const struct utimbuf *times); 308int mingw_utime(const char *file_name, const struct utimbuf *times);
309NOIMPL(utimes,const char *filename UNUSED_PARAM, const struct timeval times[2] UNUSED_PARAM); 309int utimes(const char *file_name, const struct timeval times[2]);
310 310
311#define utime mingw_utime 311#define utime mingw_utime
312 312
diff --git a/win32/mingw.c b/win32/mingw.c
index eeb96db83..c87ce2a47 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -310,6 +310,47 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
310 time_t_to_filetime(times->modtime, &mft); 310 time_t_to_filetime(times->modtime, &mft);
311 time_t_to_filetime(times->actime, &aft); 311 time_t_to_filetime(times->actime, &aft);
312 } 312 }
313 else {
314 SYSTEMTIME st;
315 GetSystemTime(&st);
316 SystemTimeToFileTime(&st, &aft);
317 mft = aft;
318 }
319 if (!SetFileTime((HANDLE)_get_osfhandle(fh), NULL, &aft, &mft)) {
320 errno = EINVAL;
321 rc = -1;
322 } else
323 rc = 0;
324 close(fh);
325 return rc;
326}
327
328static inline void timeval_to_filetime(const struct timeval tv, FILETIME *ft)
329{
330 long long winTime = ((tv.tv_sec * 1000000LL) + tv.tv_usec) * 10LL + 116444736000000000LL;
331 ft->dwLowDateTime = winTime;
332 ft->dwHighDateTime = winTime >> 32;
333}
334
335int utimes(const char *file_name, const struct timeval times[2])
336{
337 FILETIME mft, aft;
338 int fh, rc;
339
340 /* must have write permission */
341 if ((fh = open(file_name, O_RDWR | O_BINARY)) < 0)
342 return -1;
343
344 if (times) {
345 timeval_to_filetime(times[0], &aft);
346 timeval_to_filetime(times[1], &mft);
347 }
348 else {
349 SYSTEMTIME st;
350 GetSystemTime(&st);
351 SystemTimeToFileTime(&st, &aft);
352 mft = aft;
353 }
313 if (!SetFileTime((HANDLE)_get_osfhandle(fh), NULL, &aft, &mft)) { 354 if (!SetFileTime((HANDLE)_get_osfhandle(fh), NULL, &aft, &mft)) {
314 errno = EINVAL; 355 errno = EINVAL;
315 rc = -1; 356 rc = -1;