Alexandre Julliard : msvcrt: Add explicit 32- and 64-bit versions of the utime functions.

Alexandre Julliard julliard at winehq.org
Mon May 25 10:06:29 CDT 2009


Module: wine
Branch: master
Commit: 4a7b3460ef6eacc895e13b1bb35c8e6518f96fc2
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=4a7b3460ef6eacc895e13b1bb35c8e6518f96fc2

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Sat May 23 11:10:05 2009 +0200

msvcrt: Add explicit 32- and 64-bit versions of the utime functions.

---

 dlls/msvcrt/file.c          |  117 ++++++++++++++++++++++++++++++++++++------
 dlls/msvcrt/msvcrt.h        |   12 +++-
 dlls/msvcrt/msvcrt.spec     |    6 ++
 dlls/msvcrt/tests/headers.c |    9 ++-
 include/msvcrt/sys/utime.h  |   29 ++++++++++-
 5 files changed, 147 insertions(+), 26 deletions(-)

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 7e1210c..dd15b5d 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -141,6 +141,16 @@ static void msvcrt_stat64_to_stati64(const struct MSVCRT__stat64 *buf64, struct
     buf->st_ctime = buf64->st_ctime;
 }
 
+static void time_to_filetime( MSVCRT___time64_t time, FILETIME *ft )
+{
+    /* 1601 to 1970 is 369 years plus 89 leap days */
+    static const __int64 secs_1601_to_1970 = ((369 * 365 + 89) * (__int64)86400);
+
+    __int64 ticks = (time + secs_1601_to_1970) * 10000000;
+    ft->dwHighDateTime = ticks >> 32;
+    ft->dwLowDateTime = ticks;
+}
+
 static inline BOOL msvcrt_is_valid_fd(int fd)
 {
   return fd >= 0 && fd < MSVCRT_fdend && (MSVCRT_fdesc[fd].wxflag & WX_OPEN);
@@ -1213,27 +1223,22 @@ int CDECL MSVCRT__fstat(int fd, struct MSVCRT__stat* buf)
 }
 
 /*********************************************************************
- *		_futime (MSVCRT.@)
+ *		_futime64 (MSVCRT.@)
  */
-int CDECL _futime(int fd, struct MSVCRT__utimbuf *t)
+int CDECL _futime64(int fd, struct MSVCRT___utimbuf64 *t)
 {
   HANDLE hand = msvcrt_fdtoh(fd);
   FILETIME at, wt;
 
   if (!t)
   {
-    MSVCRT_time_t currTime;
-    MSVCRT_time(&currTime);
-    RtlSecondsSince1970ToTime(currTime, (LARGE_INTEGER *)&at);
-    wt = at;
+      time_to_filetime( MSVCRT__time64(NULL), &at );
+      wt = at;
   }
   else
   {
-    RtlSecondsSince1970ToTime(t->actime, (LARGE_INTEGER *)&at);
-    if (t->actime == t->modtime)
-      wt = at;
-    else
-      RtlSecondsSince1970ToTime(t->modtime, (LARGE_INTEGER *)&wt);
+      time_to_filetime( t->actime, &at );
+      time_to_filetime( t->modtime, &wt );
   }
 
   if (!SetFileTime(hand, NULL, &at, &wt))
@@ -1245,6 +1250,32 @@ int CDECL _futime(int fd, struct MSVCRT__utimbuf *t)
 }
 
 /*********************************************************************
+ *		_futime32 (MSVCRT.@)
+ */
+int CDECL _futime32(int fd, struct MSVCRT___utimbuf32 *t)
+{
+    struct MSVCRT___utimbuf64 t64;
+    t64.actime = t->actime;
+    t64.modtime = t->modtime;
+    return _futime64( fd, &t64 );
+}
+
+/*********************************************************************
+ *		_futime (MSVCRT.@)
+ */
+#ifdef _WIN64
+int CDECL _futime(int fd, struct MSVCRT___utimbuf64 *t)
+{
+    return _futime64( fd, t );
+}
+#else
+int CDECL _futime(int fd, struct MSVCRT___utimbuf32 *t)
+{
+    return _futime32( fd, t );
+}
+#endif
+
+/*********************************************************************
  *		_get_osfhandle (MSVCRT.@)
  */
 MSVCRT_intptr_t CDECL _get_osfhandle(int fd)
@@ -2053,15 +2084,15 @@ int CDECL MSVCRT__umask(int umask)
 }
 
 /*********************************************************************
- *		_utime (MSVCRT.@)
+ *		_utime64 (MSVCRT.@)
  */
-int CDECL _utime(const char* path, struct MSVCRT__utimbuf *t)
+int CDECL _utime64(const char* path, struct MSVCRT___utimbuf64 *t)
 {
   int fd = MSVCRT__open(path, MSVCRT__O_WRONLY | MSVCRT__O_BINARY);
 
   if (fd > 0)
   {
-    int retVal = _futime(fd, t);
+    int retVal = _futime64(fd, t);
     MSVCRT__close(fd);
     return retVal;
   }
@@ -2069,15 +2100,41 @@ int CDECL _utime(const char* path, struct MSVCRT__utimbuf *t)
 }
 
 /*********************************************************************
- *		_wutime (MSVCRT.@)
+ *		_utime32 (MSVCRT.@)
+ */
+int CDECL _utime32(const char* path, struct MSVCRT___utimbuf32 *t)
+{
+    struct MSVCRT___utimbuf64 t64;
+    t64.actime = t->actime;
+    t64.modtime = t->modtime;
+    return _utime64( path, &t64 );
+}
+
+/*********************************************************************
+ *		_utime (MSVCRT.@)
  */
-int CDECL _wutime(const MSVCRT_wchar_t* path, struct MSVCRT__utimbuf *t)
+#ifdef _WIN64
+int CDECL _utime(const char* path, struct MSVCRT___utimbuf64 *t)
+{
+    return _utime64( path, t );
+}
+#else
+int CDECL _utime(const char* path, struct MSVCRT___utimbuf32 *t)
+{
+    return _utime32( path, t );
+}
+#endif
+
+/*********************************************************************
+ *		_wutime64 (MSVCRT.@)
+ */
+int CDECL _wutime64(const MSVCRT_wchar_t* path, struct MSVCRT___utimbuf64 *t)
 {
   int fd = _wopen(path, MSVCRT__O_WRONLY | MSVCRT__O_BINARY);
 
   if (fd > 0)
   {
-    int retVal = _futime(fd, t);
+    int retVal = _futime64(fd, t);
     MSVCRT__close(fd);
     return retVal;
   }
@@ -2085,6 +2142,32 @@ int CDECL _wutime(const MSVCRT_wchar_t* path, struct MSVCRT__utimbuf *t)
 }
 
 /*********************************************************************
+ *		_wutime32 (MSVCRT.@)
+ */
+int CDECL _wutime32(const MSVCRT_wchar_t* path, struct MSVCRT___utimbuf32 *t)
+{
+    struct MSVCRT___utimbuf64 t64;
+    t64.actime = t->actime;
+    t64.modtime = t->modtime;
+    return _wutime64( path, &t64 );
+}
+
+/*********************************************************************
+ *		_wutime (MSVCRT.@)
+ */
+#ifdef _WIN64
+int CDECL _wutime(const MSVCRT_wchar_t* path, struct MSVCRT___utimbuf64 *t)
+{
+    return _wutime64( path, t );
+}
+#else
+int CDECL _wutime(const MSVCRT_wchar_t* path, struct MSVCRT___utimbuf32 *t)
+{
+    return _wutime32( path, t );
+}
+#endif
+
+/*********************************************************************
  *		_write (MSVCRT.@)
  */
 int CDECL MSVCRT__write(int fd, const void* buf, unsigned int count)
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index 70ad8e2..c10c8d3 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -335,10 +335,16 @@ struct MSVCRT__wfinddatai64_t {
   MSVCRT_wchar_t  name[260];
 };
 
-struct MSVCRT__utimbuf
+struct MSVCRT___utimbuf32
 {
-    MSVCRT_time_t actime;
-    MSVCRT_time_t modtime;
+    MSVCRT___time32_t actime;
+    MSVCRT___time32_t modtime;
+};
+
+struct MSVCRT___utimbuf64
+{
+    MSVCRT___time64_t actime;
+    MSVCRT___time64_t modtime;
 };
 
 /* for FreeBSD */
diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index 759d0c0..b56aba0 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -272,6 +272,8 @@
 @ cdecl -ret64 _ftol() ntdll._ftol
 @ cdecl _fullpath(ptr str long)
 @ cdecl _futime(long ptr)
+@ cdecl _futime32(long ptr)
+@ cdecl _futime64(long ptr)
 @ cdecl _gcvt(double long str)
 @ cdecl _get_osfhandle(long)
 @ cdecl _get_sbh_threshold()
@@ -521,6 +523,8 @@
 @ cdecl _unlink(str) MSVCRT__unlink
 @ cdecl _unloaddll(long)
 @ cdecl _unlock(long)
+@ cdecl _utime32(str ptr)
+@ cdecl _utime64(str ptr)
 @ cdecl _utime(str ptr)
 @ cdecl _vscprintf(str ptr)
 @ cdecl _vscwprintf(wstr ptr)
@@ -608,6 +612,8 @@
 @ cdecl _wtol(wstr) ntdll._wtol
 @ cdecl _wunlink(wstr)
 @ cdecl _wutime(wstr ptr)
+@ cdecl _wutime32(wstr ptr)
+@ cdecl _wutime64(wstr ptr)
 @ cdecl _y0(double)
 @ cdecl _y1(double)
 @ cdecl _yn(long double )
diff --git a/dlls/msvcrt/tests/headers.c b/dlls/msvcrt/tests/headers.c
index 603134f..b9fdbd7 100644
--- a/dlls/msvcrt/tests/headers.c
+++ b/dlls/msvcrt/tests/headers.c
@@ -219,9 +219,12 @@ static void test_structs(void)
     CHECK_FIELD(_wfinddatai64_t, time_write);
     CHECK_FIELD(_wfinddatai64_t, size);
     CHECK_FIELD(_wfinddatai64_t, name[260]);
-    CHECK_STRUCT(_utimbuf);
-    CHECK_FIELD(_utimbuf, actime);
-    CHECK_FIELD(_utimbuf, modtime);
+    CHECK_STRUCT(__utimbuf32);
+    CHECK_FIELD(__utimbuf32, actime);
+    CHECK_FIELD(__utimbuf32, modtime);
+    CHECK_STRUCT(__utimbuf64);
+    CHECK_FIELD(__utimbuf64, actime);
+    CHECK_FIELD(__utimbuf64, modtime);
     CHECK_STRUCT(_stat);
     CHECK_FIELD(_stat, st_dev);
     CHECK_FIELD(_stat, st_ino);
diff --git a/include/msvcrt/sys/utime.h b/include/msvcrt/sys/utime.h
index 95b1f9b..014351b 100644
--- a/include/msvcrt/sys/utime.h
+++ b/include/msvcrt/sys/utime.h
@@ -31,15 +31,38 @@ struct _utimbuf
     time_t actime;
     time_t modtime;
 };
+struct __utimbuf32
+{
+    __time32_t actime;
+    __time32_t modtime;
+};
+struct __utimbuf64
+{
+    __time64_t actime;
+    __time64_t modtime;
+};
 #endif /* _UTIMBUF_DEFINED */
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-int __cdecl _futime(int,struct _utimbuf*);
-int __cdecl _utime(const char*,struct _utimbuf*);
-int __cdecl _wutime(const wchar_t*,struct _utimbuf*);
+int __cdecl _futime32(int,struct __utimbuf32*);
+int __cdecl _futime64(int,struct __utimbuf64*);
+int __cdecl _utime32(const char*,struct __utimbuf32*);
+int __cdecl _utime64(const char*,struct __utimbuf64*);
+int __cdecl _wutime32(const wchar_t*,struct __utimbuf32*);
+int __cdecl _wutime64(const wchar_t*,struct __utimbuf64*);
+
+#ifdef _USE_32BIT_TIME_T
+static inline int _futime(int fd, struct _utimbuf *buf) { return _futime32(fd, (struct __utimbuf32*)buf); }
+static inline int _utime(const char *s, struct _utimbuf *buf) { return _utime32(s, (struct __utimbuf32*)buf); }
+static inline int _wutime(const wchar_t *s, struct _utimbuf *buf) { return _wutime32(s, (struct __utimbuf32*)buf); }
+#else
+static inline int _futime(int fd, struct _utimbuf *buf) { return _futime64(fd, (struct __utimbuf64*)buf); }
+static inline int _utime(const char *s, struct _utimbuf *buf) { return _utime64(s, (struct __utimbuf64*)buf); }
+static inline int _wutime(const wchar_t *s, struct _utimbuf *buf) { return _wutime64(s, (struct __utimbuf64*)buf); }
+#endif
 
 #ifdef __cplusplus
 }




More information about the wine-cvs mailing list