fix improper utimes usage
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 29 Nov 2009 18:40:36 +0000 (19:40 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 29 Nov 2009 18:40:36 +0000 (19:40 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/bbunzip.c
archival/libunarchive/data_extract_all.c
coreutils/touch.c
libbb/copy_file.c

index 22a0fd189d4d05cb0b2181899095b2bad0b1c970..df674bc6cd43a27839b036d028ca32f9457093f7 100644 (file)
@@ -105,15 +105,15 @@ int FAST_FUNC bbunpack(char **argv,
                        if (status >= 0) {
                                /* TODO: restore other things? */
                                if (info.mtime) {
-                                       struct timeval times;
+                                       struct timeval times[2];
 
-                                       times.tv_sec = info.mtime;
-                                       times.tv_usec = 0;
+                                       times[1].tv_sec = times[0].tv_sec = info.mtime;
+                                       times[1].tv_usec = times[0].tv_usec = 0;
                                        /* Note: we closed it first.
                                         * On some systems calling utimes
                                         * then closing resets the mtime
                                         * back to current time. */
-                                       utimes(new_name, &times); /* ignoring errors */
+                                       utimes(new_name, times); /* ignoring errors */
                                }
 
                                /* Delete _compressed_ file */
index 1100410e6192854790dcbf6baa0abd2b4eb95408..ae242df64256309db007d63fe655e3e2635aa090 100644 (file)
@@ -148,11 +148,11 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
                }
                /* same for utime */
                if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) {
-                       struct timeval t;
+                       struct timeval t[2];
 
-                       t.tv_sec = file_header->mtime;
-                       t.tv_usec = 0;
-                       utimes(file_header->name, &t);
+                       t[1].tv_sec = t[0].tv_sec = file_header->mtime;
+                       t[1].tv_usec = t[0].tv_usec = 0;
+                       utimes(file_header->name, t);
                }
        }
 }
index f670b7f6edb951e3e7ef64e87be043fde5d81a82..be2d2f92584060030bfd4a870e5483e14f7fd5ec 100644 (file)
@@ -54,8 +54,8 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
 # endif
        char *reference_file = NULL;
        char *date_str = NULL;
-       struct timeval timebuf;
-       timebuf.tv_usec = 0;
+       struct timeval timebuf[2];
+       timebuf[1].tv_usec = timebuf[0].tv_usec = 0;
 #else
 # define reference_file NULL
 # define date_str       NULL
@@ -84,7 +84,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
        if (reference_file) {
                struct stat stbuf;
                xstat(reference_file, &stbuf);
-               timebuf.tv_sec = stbuf.st_mtime;
+               timebuf[1].tv_sec = timebuf[0].tv_sec = stbuf.st_mtime;
        }
 
        if (date_str) {
@@ -100,11 +100,11 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
                tm_time.tm_isdst = -1;  /* Be sure to recheck dst */
                t = validate_tm_time(date_str, &tm_time);
 
-               timebuf.tv_sec = t;
+               timebuf[1].tv_sec = timebuf[0].tv_sec = t;
        }
 
        do {
-               if (utimes(*argv, reference_file ? &timebuf : NULL)) {
+               if (utimes(*argv, reference_file ? timebuf : NULL)) {
                        if (errno == ENOENT) { /* no such file */
                                if (opts) { /* creation is disabled, so ignore */
                                        continue;
@@ -115,7 +115,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
                                                  );
                                if ((fd >= 0) && !close(fd)) {
                                        if (reference_file)
-                                               utimes(*argv, &timebuf);
+                                               utimes(*argv, timebuf);
                                        continue;
                                }
                        }
index adcfe2111f23dc68bb7b8619779fb2abce6b6862..893b52ed526cf837057b106ee140a49f708e21be 100644 (file)
@@ -374,12 +374,12 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
        /* Cannot happen: */
        /* && !(flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) */
        ) {
-               struct timeval times;
+               struct timeval times[2];
 
-               times.tv_sec = source_stat.st_mtime;
-               times.tv_usec = 0;
+               times[1].tv_sec = times[0].tv_sec = source_stat.st_mtime;
+               times[1].tv_usec = times[0].tv_usec = 0;
                /* BTW, utimes sets usec-precision time - just FYI */
-               if (utimes(dest, &times) < 0)
+               if (utimes(dest, times) < 0)
                        bb_perror_msg("can't preserve %s of '%s'", "times", dest);
                if (chown(dest, source_stat.st_uid, source_stat.st_gid) < 0) {
                        source_stat.st_mode &= ~(S_ISUID | S_ISGID);