Skip to content

Commit b55d255

Browse files
committed
unzip: fix build without utimensat() or futimens()
Fixes libarchive#1919
1 parent 852611e commit b55d255

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

unzip/bsdunzip.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
#ifdef HAVE_UNISTD_H
7373
#include <unistd.h>
7474
#endif
75+
#if ((!defined(HAVE_UTIMENSAT) && defined(HAVE_LUTIMES)) || \
76+
(!defined(HAVE_FUTIMENS) && defined(HAVE_FUTIMES)))
77+
#ifdef HAVE_SYS_TIME_H
78+
#include <sys/time.h>
79+
#endif
80+
#endif
7581

7682
#include <archive.h>
7783
#include <archive_entry.h>
@@ -630,9 +636,15 @@ extract_file(struct archive *a, struct archive_entry *e, char **path)
630636
int mode;
631637
struct timespec mtime;
632638
struct stat sb;
633-
struct timespec ts[2];
634639
int fd, check, text;
635640
const char *linkname;
641+
#if defined(HAVE_UTIMENSAT) || defined(HAVE_FUTIMENS)
642+
struct timespec ts[2];
643+
#endif
644+
#if ((!defined(HAVE_UTIMENSAT) && defined(HAVE_LUTIMES)) || \
645+
(!defined(HAVE_FUTIMENS) && defined(HAVE_FUTIMES)))
646+
struct timeval times[2];
647+
#endif
636648

637649
mode = archive_entry_mode(e) & 0777;
638650
if (mode == 0)
@@ -686,9 +698,18 @@ extract_file(struct archive *a, struct archive_entry *e, char **path)
686698
return;
687699
}
688700

701+
#if defined(HAVE_UTIMENSAT) || defined(HAVE_FUTIMENS)
689702
ts[0].tv_sec = 0;
690703
ts[0].tv_nsec = UTIME_NOW;
691704
ts[1] = mtime;
705+
#endif
706+
#if ((!defined(HAVE_UTIMENSAT) && defined(HAVE_LUTIMES)) || \
707+
(!defined(HAVE_FUTIMENS) && defined(HAVE_FUTIMES)))
708+
times[0].tv_sec = 0;
709+
times[0].tv_usec = -1;
710+
times[1].tv_sec = mtime.tv_sec;
711+
times[1].tv_usec = mtime.tv_nsec / 1000;
712+
#endif
692713

693714
/* process symlinks */
694715
linkname = archive_entry_symlink(e);
@@ -701,8 +722,14 @@ extract_file(struct archive *a, struct archive_entry *e, char **path)
701722
warning("Cannot set mode for '%s'", *path);
702723
#endif
703724
/* set access and modification time */
725+
#if defined(HAVE_UTIMENSAT)
704726
if (utimensat(AT_FDCWD, *path, ts, AT_SYMLINK_NOFOLLOW) != 0)
705727
warning("utimensat('%s')", *path);
728+
#elif defined(HAVE_LUTIMES)
729+
gettimeofday(&times[0], NULL);
730+
if (lutimes(*path, times) != 0)
731+
warning("lutimes('%s')", *path);
732+
#endif
706733
return;
707734
}
708735

@@ -720,8 +747,14 @@ extract_file(struct archive *a, struct archive_entry *e, char **path)
720747
info("\n");
721748

722749
/* set access and modification time */
750+
#if defined(HAVE_FUTIMENS)
723751
if (futimens(fd, ts) != 0)
724752
error("futimens('%s')", *path);
753+
#elif defined(HAVE_FUTIMES)
754+
gettimeofday(&times[0], NULL);
755+
if (futimes(fd, times) != 0)
756+
error("futimes('%s')", *path);
757+
#endif
725758
if (close(fd) != 0)
726759
error("close('%s')", *path);
727760
}

0 commit comments

Comments
 (0)