+ This routine should *not* be called twice for the same block, since
+ the two calls might use different DO_USER_GROUP values and thus
+ might end up with different uid/gid for the two calls. If anybody
+ wants the uid/gid they should decode it first, and other callers
+ should decode it without uid/gid before calling a routine,
+ e.g. print_header, that assumes decoded data. */
+void
+decode_header (union block *header, struct tar_stat_info *stat_info,
+ enum archive_format *format_pointer, int do_user_group)
+{
+ enum archive_format format;
+
+ if (strcmp (header->header.magic, TMAGIC) == 0)
+ {
+ if (header->star_header.prefix[130] == 0
+ && ISOCTAL (header->star_header.atime[0])
+ && header->star_header.atime[11] == ' '
+ && ISOCTAL (header->star_header.ctime[0])
+ && header->star_header.ctime[11] == ' ')
+ format = STAR_FORMAT;
+ else if (extended_header.size)
+ format = POSIX_FORMAT;
+ else
+ format = USTAR_FORMAT;
+ }
+ else if (strcmp (header->header.magic, OLDGNU_MAGIC) == 0)
+ format = OLDGNU_FORMAT;
+ else
+ format = V7_FORMAT;
+ *format_pointer = format;
+
+ stat_info->stat.st_mode = MODE_FROM_HEADER (header->header.mode);
+ stat_info->mtime.tv_sec = TIME_FROM_HEADER (header->header.mtime);
+ stat_info->mtime.tv_nsec = 0;
+ assign_string (&stat_info->uname,
+ header->header.uname[0] ? header->header.uname : NULL);
+ assign_string (&stat_info->gname,
+ header->header.gname[0] ? header->header.gname : NULL);
+
+ if (format == OLDGNU_FORMAT && incremental_option)
+ {
+ stat_info->atime.tv_sec = TIME_FROM_HEADER (header->oldgnu_header.atime);
+ stat_info->ctime.tv_sec = TIME_FROM_HEADER (header->oldgnu_header.ctime);
+ stat_info->atime.tv_nsec = stat_info->ctime.tv_nsec = 0;
+ }
+ else if (format == STAR_FORMAT)
+ {
+ stat_info->atime.tv_sec = TIME_FROM_HEADER (header->star_header.atime);
+ stat_info->ctime.tv_sec = TIME_FROM_HEADER (header->star_header.ctime);
+ stat_info->atime.tv_nsec = stat_info->ctime.tv_nsec = 0;
+ }
+ else
+ stat_info->atime = stat_info->ctime = start_time;
+
+ if (format == V7_FORMAT)
+ {
+ stat_info->stat.st_uid = UID_FROM_HEADER (header->header.uid);
+ stat_info->stat.st_gid = GID_FROM_HEADER (header->header.gid);
+ stat_info->stat.st_rdev = 0;
+ }
+ else
+ {
+ if (do_user_group)
+ {
+ /* FIXME: Decide if this should somewhat depend on -p. */
+
+ if (numeric_owner_option
+ || !*header->header.uname
+ || !uname_to_uid (header->header.uname, &stat_info->stat.st_uid))
+ stat_info->stat.st_uid = UID_FROM_HEADER (header->header.uid);
+
+ if (numeric_owner_option
+ || !*header->header.gname
+ || !gname_to_gid (header->header.gname, &stat_info->stat.st_gid))
+ stat_info->stat.st_gid = GID_FROM_HEADER (header->header.gid);
+ }
+
+ switch (header->header.typeflag)
+ {
+ case BLKTYPE:
+ case CHRTYPE:
+ stat_info->stat.st_rdev =
+ makedev (MAJOR_FROM_HEADER (header->header.devmajor),
+ MINOR_FROM_HEADER (header->header.devminor));
+ break;
+
+ default:
+ stat_info->stat.st_rdev = 0;
+ }
+ }
+
+ stat_info->archive_file_size = stat_info->stat.st_size;
+ xheader_decode (stat_info);
+
+ if (sparse_member_p (stat_info))
+ {
+ sparse_fixup_header (stat_info);
+ stat_info->is_sparse = true;
+ }
+ else
+ {
+ stat_info->is_sparse = false;
+ if ((current_format == GNU_FORMAT
+ || current_format == OLDGNU_FORMAT)
+ && current_header->header.typeflag == GNUTYPE_DUMPDIR)
+ get_gnu_dumpdir ();
+ }
+}
+
+/* Convert buffer at WHERE0 of size DIGS from external format to
+ uintmax_t. DIGS must be positive. If TYPE is nonnull, the data
+ are of type TYPE. The buffer must represent a value in the range
+ -MINUS_MINVAL through MAXVAL. If OCTAL_ONLY, allow only octal
+ numbers instead of the other GNU extensions. Return -1 on error,
+ diagnosing the error if TYPE is nonnull and if !SILENT. */
+static uintmax_t
+from_header (char const *where0, size_t digs, char const *type,
+ uintmax_t minus_minval, uintmax_t maxval,
+ bool octal_only, bool silent)