diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-04-06 17:23:16 +0200 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-04-20 19:14:33 +0200 |
commit | fd704aa0db21aa03938b824b409107504d7c3482 (patch) | |
tree | 8323ffe4a0e1550d9f29531cf2f2a5f0c433fbed | |
parent | 65eefca7c9e72f9ed7363cd08a3cea83dfea5b40 (diff) | |
download | busybox-w32-fd704aa0db21aa03938b824b409107504d7c3482.tar.gz busybox-w32-fd704aa0db21aa03938b824b409107504d7c3482.tar.bz2 busybox-w32-fd704aa0db21aa03938b824b409107504d7c3482.zip |
win32: add utimes and fix utime(file,NULL)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
-rw-r--r-- | include/mingw.h | 2 | ||||
-rw-r--r-- | win32/mingw.c | 41 |
2 files changed, 42 insertions, 1 deletions
diff --git a/include/mingw.h b/include/mingw.h index 8931e719e..7ec21b72d 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -321,7 +321,7 @@ NOIMPL(vfork,void); | |||
321 | * utime.h | 321 | * utime.h |
322 | */ | 322 | */ |
323 | int mingw_utime(const char *file_name, const struct utimbuf *times); | 323 | int mingw_utime(const char *file_name, const struct utimbuf *times); |
324 | NOIMPL(utimes,const char *filename UNUSED_PARAM, const struct timeval times[2] UNUSED_PARAM); | 324 | int utimes(const char *file_name, const struct timeval times[2]); |
325 | 325 | ||
326 | #define utime mingw_utime | 326 | #define utime mingw_utime |
327 | 327 | ||
diff --git a/win32/mingw.c b/win32/mingw.c index 669b3eec3..a412f5249 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 | |||
328 | static 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 | |||
335 | int 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; |