]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
unzip: fix build without utimensat() or futimens()
authorMartin Matuska <martin@matuska.de>
Tue, 18 Jul 2023 14:57:10 +0000 (16:57 +0200)
committerMartin Matuska <martin@matuska.de>
Wed, 19 Jul 2023 07:10:36 +0000 (09:10 +0200)
Fixes #1919

unzip/bsdunzip.c

index be18ecfb55bde4d5d853518dd1b28be68365e27d..cd8237aa7059fe6912ce5c8ba67fa6b396e480d8 100644 (file)
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#if ((!defined(HAVE_UTIMENSAT) && defined(HAVE_LUTIMES)) || \
+    (!defined(HAVE_FUTIMENS) && defined(HAVE_FUTIMES)))
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#endif
 
 #include <archive.h>
 #include <archive_entry.h>
@@ -630,9 +636,15 @@ extract_file(struct archive *a, struct archive_entry *e, char **path)
        int mode;
        struct timespec mtime;
        struct stat sb;
-       struct timespec ts[2];
        int fd, check, text;
        const char *linkname;
+#if defined(HAVE_UTIMENSAT) || defined(HAVE_FUTIMENS)
+       struct timespec ts[2];
+#endif
+#if ((!defined(HAVE_UTIMENSAT) && defined(HAVE_LUTIMES)) || \
+    (!defined(HAVE_FUTIMENS) && defined(HAVE_FUTIMES)))
+       struct timeval times[2];
+#endif
 
        mode = archive_entry_mode(e) & 0777;
        if (mode == 0)
@@ -686,9 +698,18 @@ recheck:
                        return;
        }
 
+#if defined(HAVE_UTIMENSAT) || defined(HAVE_FUTIMENS)
        ts[0].tv_sec = 0;
        ts[0].tv_nsec = UTIME_NOW;
        ts[1] = mtime;
+#endif
+#if ((!defined(HAVE_UTIMENSAT) && defined(HAVE_LUTIMES)) || \
+    (!defined(HAVE_FUTIMENS) && defined(HAVE_FUTIMES)))
+       times[0].tv_sec = 0;
+       times[0].tv_usec = -1;
+       times[1].tv_sec = mtime.tv_sec;
+       times[1].tv_usec = mtime.tv_nsec / 1000;
+#endif
 
        /* process symlinks */
        linkname = archive_entry_symlink(e);
@@ -701,8 +722,14 @@ recheck:
                        warning("Cannot set mode for '%s'", *path);
 #endif
                /* set access and modification time */
+#if defined(HAVE_UTIMENSAT)
                if (utimensat(AT_FDCWD, *path, ts, AT_SYMLINK_NOFOLLOW) != 0)
                        warning("utimensat('%s')", *path);
+#elif defined(HAVE_LUTIMES)
+               gettimeofday(&times[0], NULL);
+               if (lutimes(*path, times) != 0)
+                       warning("lutimes('%s')", *path);
+#endif
                return;
        }
 
@@ -720,8 +747,14 @@ recheck:
        info("\n");
 
        /* set access and modification time */
+#if defined(HAVE_FUTIMENS)
        if (futimens(fd, ts) != 0)
                error("futimens('%s')", *path);
+#elif defined(HAVE_FUTIMES)
+       gettimeofday(&times[0], NULL);
+       if (futimes(fd, times) != 0)
+               error("futimes('%s')", *path);
+#endif
        if (close(fd) != 0)
                error("close('%s')", *path);
 }