From: Eli Zaretskii Date: Sat, 24 Aug 2013 10:15:01 +0000 (+0300) Subject: Fix bug #15176 with setting directory times on MS-Windows. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1686^2~134 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b34454d067efe26983f32ee6dc725d5122de58f4;p=emacs.git Fix bug #15176 with setting directory times on MS-Windows. src/w32.c (fdutimens): Call 'utime', which is implemented on w32.c to handle directories, rather than '_utime' which doesn't. --- diff --git a/src/ChangeLog b/src/ChangeLog index 8e5eedd445c..2bb41071fd6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2013-08-24 Eli Zaretskii + + * 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 * gtkutil.c (x_wm_set_size_hint): Don't set hints when maximized diff --git a/src/w32.c b/src/w32.c index 21dbf49ed7c..7f9b96a77a5 100644 --- 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) {