]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
futimes() and utimes() emulations for Windows.
authorTim Kientzle <kientzle@gmail.com>
Mon, 29 Dec 2008 00:21:35 +0000 (19:21 -0500)
committerTim Kientzle <kientzle@gmail.com>
Mon, 29 Dec 2008 00:21:35 +0000 (19:21 -0500)
Submitted by: Michihiro NAKAJIMA

SVN-Revision: 300

libarchive/archive_windows.c
libarchive/archive_windows.h

index 1f4d273dabb1627311c8ed8920dc892530e18a2c..579bb45ef88e7fa18b5f3863426bf56a7a63fb32 100644 (file)
@@ -185,4 +185,50 @@ int fstati64 (int fd, struct _stati64 *st)
        return res;
 }
 
+#define WINTIME(sec, usec)     ((Int32x32To64(sec, 10000000) + 116444736000000000) + (usec * 10))
+static int
+__hutimes(HANDLE handle, const struct __timeval *times)
+{
+       uint64_t wintm;
+       FILETIME fatime, fmtime;
+
+       wintm = WINTIME(times[0].tv_sec, times[0].tv_usec);
+       fatime.dwLowDateTime = (DWORD)wintm;
+       fatime.dwHighDateTime = wintm >> 32;
+       wintm = WINTIME(times[1].tv_sec, times[1].tv_usec);
+       fmtime.dwLowDateTime = (DWORD)wintm;
+       fmtime.dwHighDateTime = wintm >> 32;
+       if (SetFileTime(handle, NULL, &fatime, &fmtime) == 0) {
+               errno = EINVAL;
+               return (-1);
+       }
+       return (0);
+}
+
+int
+futimes(int fd, const struct __timeval *times)
+{
+
+       return (__hutimes((HANDLE)_get_osfhandle(fd), times));
+}
+
+int
+utimes(const char *name, const struct __timeval *times)
+{
+       int ret;
+       HANDLE handle;
+
+       handle = CreateFile(name, GENERIC_READ | GENERIC_WRITE,
+           FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
+           0, NULL);
+       if (handle == INVALID_HANDLE_VALUE) {
+               errno = EINVAL;
+               return (-1);
+       }
+       ret = __hutimes(handle, times);
+       CloseHandle(handle);
+       return (ret);
+}
+
+
 #endif /* _WIN32 */
index 5d5d2d61e0139273ef7f734dcb2571960636ce78..3bb7645b5253d3e9878867638a272be81817ddee 100644 (file)
 #endif /* __MINGW32__ */
 #endif /* LARGE_FILES */
 
+#ifdef USE_WINSOCK_TIMEVAL
+/* Winsock timeval has long size tv_sec. */
+#define __timeval timeval
+#else
+struct _timeval64i32 {
+       time_t          tv_sec;
+       long            tv_usec;
+};
+#define __timeval _timeval64i32
+#endif
+
 /* End of Win32 definitions. */
 
 #ifdef __cplusplus
@@ -247,6 +258,9 @@ extern "C" {
 
 extern int link (const char *from, const char *to);
 extern int symlink (const char *from, const char *to);
+extern int _dosmaperr(unsigned long);
+extern int futimes(int fd, const struct __timeval *times);
+extern int utimes(const char *name, const struct __timeval *times);
 
 #ifdef __cplusplus
 }