Skip to content

Commit

Permalink
unzip: fix build without utimensat() or futimens()
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatuska committed Jul 18, 2023
1 parent 852611e commit 035d517
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion unzip/bsdunzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
#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>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -686,9 +698,18 @@ extract_file(struct archive *a, struct archive_entry *e, char **path)
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);
Expand All @@ -701,8 +722,14 @@ extract_file(struct archive *a, struct archive_entry *e, char **path)
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;
}

Expand All @@ -720,8 +747,14 @@ extract_file(struct archive *a, struct archive_entry *e, char **path)
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);
}
Expand Down

0 comments on commit 035d517

Please sign in to comment.