+ /* This is nonportable (the type of set_next_block_after's arg). */
+
+ set_next_block_after (start + (count - 1) / BLOCKSIZE);
+
+ if (count == bufsize)
+ continue;
+ else
+ {
+ char buf[UINTMAX_STRSIZE_BOUND];
+ ERROR ((0, 0,
+ _("File %s shrunk by %s bytes, padding with zeros"),
+ p, STRINGIFY_BIGINT (sizeleft, buf)));
+ goto padit; /* short read */
+ }
+ }
+
+ if (multi_volume_option)
+ assign_string (&save_name, 0);
+
+ if (f >= 0)
+ {
+ struct stat final_stat;
+ if (fstat (f, &final_stat) != 0)
+ ERROR ((0, errno, "%s: fstat", p));
+ else if (final_stat.st_mtime != restore_times.modtime
+ || final_stat.st_size != restore_size)
+ ERROR ((0, errno, _("%s: file changed as we read it"), p));
+ if (close (f) != 0)
+ ERROR ((0, errno, _("%s: close"), p));
+ if (atime_preserve_option)
+ utime (p, &restore_times);
+ }
+ if (remove_files_option)
+ {
+ if (unlink (p) == -1)
+ ERROR ((0, errno, _("Cannot remove %s"), p));
+ }
+ return;
+
+ /* File shrunk or gave error, pad out tape to match the size we
+ specified in the header. */
+
+ padit:
+ while (sizeleft > 0)
+ {
+ save_sizeleft = sizeleft;
+ start = find_next_block ();
+ memset (start->buffer, 0, BLOCKSIZE);
+ set_next_block_after (start);
+ sizeleft -= BLOCKSIZE;
+ }
+ if (multi_volume_option)
+ assign_string (&save_name, 0);
+ if (f >= 0)
+ {
+ close (f);
+ if (atime_preserve_option)
+ utime (p, &restore_times);
+ }
+ return;
+ }
+#ifdef HAVE_READLINK
+ else if (S_ISLNK (current_stat.st_mode))
+ {
+ int size;
+ char *buffer = (char *) alloca (PATH_MAX + 1);
+
+ size = readlink (p, buffer, PATH_MAX + 1);
+ if (size < 0)
+ {
+ WARN ((0, errno, _("Cannot add file %s"), p));
+ if (!ignore_failed_read_option)
+ exit_status = TAREXIT_FAILURE;
+ return;
+ }
+ buffer[size] = '\0';
+ if (size >= NAME_FIELD_SIZE)
+ write_long (buffer, GNUTYPE_LONGLINK);
+ assign_string (¤t_link_name, buffer);
+
+ current_stat.st_size = 0; /* force 0 size on symlink */
+ header = start_header (p, ¤t_stat);
+ strncpy (header->header.linkname, buffer, NAME_FIELD_SIZE);
+ header->header.linkname[NAME_FIELD_SIZE - 1] = '\0';
+ header->header.typeflag = SYMTYPE;
+ finish_header (header); /* nothing more to do to it */
+ if (remove_files_option)
+ {
+ if (unlink (p) == -1)
+ ERROR ((0, errno, _("Cannot remove %s"), p));
+ }
+ return;
+ }
+#endif
+ else if (S_ISCHR (current_stat.st_mode))
+ type = CHRTYPE;
+ else if (S_ISBLK (current_stat.st_mode))
+ type = BLKTYPE;
+ else if (S_ISFIFO (current_stat.st_mode)
+ || S_ISSOCK (current_stat.st_mode))
+ type = FIFOTYPE;
+ else
+ goto unknown;
+ }
+
+ if (archive_format == V7_FORMAT)
+ goto unknown;
+
+ current_stat.st_size = 0; /* force 0 size */
+ header = start_header (p, ¤t_stat);
+ header->header.typeflag = type;
+
+ if (type != FIFOTYPE)
+ {
+ MAJOR_TO_CHARS (major (current_stat.st_rdev), header->header.devmajor);
+ MINOR_TO_CHARS (minor (current_stat.st_rdev), header->header.devminor);
+ }