+ after_backup_name = find_backup_file_name (file_name, backup_type);
+ if (! after_backup_name)
+ xalloc_die ();
+
+ if (rename (before_backup_name, after_backup_name) == 0)
+ {
+ if (verbose_option)
+ fprintf (stdlis, _("Renaming %s to %s\n"),
+ quote_n (0, before_backup_name),
+ quote_n (1, after_backup_name));
+ return true;
+ }
+ else
+ {
+ /* The backup operation failed. */
+ int e = errno;
+ ERROR ((0, e, _("%s: Cannot rename to %s"),
+ quotearg_colon (before_backup_name),
+ quote_n (1, after_backup_name)));
+ assign_string (&after_backup_name, 0);
+ return false;
+ }
+}
+
+/* Try to restore the recently backed up file to its original name.
+ This is usually only needed after a failed extraction. */
+void
+undo_last_backup (void)
+{
+ if (after_backup_name)
+ {
+ if (rename (after_backup_name, before_backup_name) != 0)
+ {
+ int e = errno;
+ ERROR ((0, e, _("%s: Cannot rename to %s"),
+ quotearg_colon (after_backup_name),
+ quote_n (1, before_backup_name)));
+ }
+ if (verbose_option)
+ fprintf (stdlis, _("Renaming %s back to %s\n"),
+ quote_n (0, after_backup_name),
+ quote_n (1, before_backup_name));
+ assign_string (&after_backup_name, 0);
+ }
+}
+
+/* Depending on DEREF, apply either stat or lstat to (NAME, BUF). */
+int
+deref_stat (bool deref, char const *name, struct stat *buf)
+{
+ return deref ? stat (name, buf) : lstat (name, buf);
+}
+
+/* Set FD's (i.e., FILE's) access time to TIMESPEC[0]. If that's not
+ possible to do by itself, set its access and data modification
+ times to TIMESPEC[0] and TIMESPEC[1], respectively. */
+int
+set_file_atime (int fd, char const *file, struct timespec const timespec[2])
+{
+#ifdef _FIOSATIME
+ if (0 <= fd)
+ {
+ struct timeval timeval;
+ timeval.tv_sec = timespec[0].tv_sec;
+ timeval.tv_usec = timespec[0].tv_nsec / 1000;
+ if (ioctl (fd, _FIOSATIME, &timeval) == 0)
+ return 0;
+ }