Fix bug #15176 with setting directory times on MS-Windows.
authorEli Zaretskii <eliz@gnu.org>
Sat, 24 Aug 2013 10:15:01 +0000 (13:15 +0300)
committerEli Zaretskii <eliz@gnu.org>
Sat, 24 Aug 2013 10:15:01 +0000 (13:15 +0300)
 src/w32.c (fdutimens): Call 'utime', which is implemented on w32.c
 to handle directories, rather than '_utime' which doesn't.

src/ChangeLog
src/w32.c

index 8e5eedd..2bb4107 100644 (file)
@@ -1,3 +1,9 @@
+2013-08-24  Eli Zaretskii  <eliz@gnu.org>
+
+       * w32.c (fdutimens): Call 'utime', which is implemented on w32.c
+       to handle directories, rather than '_utime' which doesn't.
+       (Bug#15176)
+
 2013-08-24  Jan Djärv  <jan.h.d@swipnet.se>
 
        * gtkutil.c (x_wm_set_size_hint): Don't set hints when maximized
index 21dbf49..7f9b96a 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -2503,8 +2503,6 @@ gettimeofday (struct timeval *__restrict tv, struct timezone *__restrict tz)
 int
 fdutimens (int fd, char const *file, struct timespec const timespec[2])
 {
-  struct _utimbuf ut;
-
   if (!timespec)
     {
       errno = ENOSYS;
@@ -2515,12 +2513,28 @@ fdutimens (int fd, char const *file, struct timespec const timespec[2])
       errno = EBADF;
       return -1;
     }
-  ut.actime = timespec[0].tv_sec;
-  ut.modtime = timespec[1].tv_sec;
+  /* _futime's prototype defines 2nd arg as having the type 'struct
+     _utimbuf', while utime needs to accept 'struct utimbuf' for
+     compatibility with Posix.  So we need to use 2 different (but
+     equivalent) types to avoid compiler warnings, sigh.  */
   if (fd >= 0)
-    return _futime (fd, &ut);
+    {
+      struct _utimbuf _ut;
+
+      _ut.actime = timespec[0].tv_sec;
+      _ut.modtime = timespec[1].tv_sec;
+      return _futime (fd, &_ut);
+    }
   else
-    return _utime (file, &ut);
+    {
+      struct utimbuf ut;
+
+      ut.actime = timespec[0].tv_sec;
+      ut.modtime = timespec[1].tv_sec;
+      /* Call 'utime', which is implemented below, not the MS library
+        function, which fails on directories.  */
+      return utime (file, &ut);
+    }
 }
 
 
@@ -4501,6 +4515,9 @@ fstat (int desc, struct stat * buf)
   return 0;
 }
 
+/* A version of 'utime' which handles directories as well as
+   files.  */
+
 int
 utime (const char *name, struct utimbuf *times)
 {