⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.c

📁 gnu tar 源码包。 tar 软件是 Unix 系统下的一个打包软件
💻 C
📖 第 1 页 / 共 3 页
字号:
}off_toff_from_header (const char *p, size_t s){  /* Negative offsets are not allowed in tar files, so invoke     from_header with minimum value 0, not TYPE_MINIMUM (off_t).  */  return from_header (p, s, "off_t", (uintmax_t) 0,		      (uintmax_t) TYPE_MAXIMUM (off_t), false, false);}size_tsize_from_header (const char *p, size_t s){  return from_header (p, s, "size_t", (uintmax_t) 0,		      (uintmax_t) TYPE_MAXIMUM (size_t), false, false);}time_ttime_from_header (const char *p, size_t s){  return from_header (p, s, "time_t",		      - (uintmax_t) TYPE_MINIMUM (time_t),		      (uintmax_t) TYPE_MAXIMUM (time_t), false, false);}uid_tuid_from_header (const char *p, size_t s){  return from_header (p, s, "uid_t",		      - (uintmax_t) TYPE_MINIMUM (uid_t),		      (uintmax_t) TYPE_MAXIMUM (uid_t), false, false);}uintmax_tuintmax_from_header (const char *p, size_t s){  return from_header (p, s, "uintmax_t", (uintmax_t) 0,		      TYPE_MAXIMUM (uintmax_t), false, false);}/* Return a printable representation of T.  The result points to   static storage that can be reused in the next call to this   function, to ctime, or to asctime.  If FULL_TIME, then output the   time stamp to its full resolution; otherwise, just output it to   1-minute resolution.  */char const *tartime (struct timespec t, bool full_time){  enum { fraclen = sizeof ".FFFFFFFFF" - 1 };  static char buffer[max (UINTMAX_STRSIZE_BOUND + 1,			  INT_STRLEN_BOUND (int) + 16)		     + fraclen];  struct tm *tm;  time_t s = t.tv_sec;  int ns = t.tv_nsec;  bool negative = s < 0;  char *p;  if (negative && ns != 0)    {      s++;      ns = 1000000000 - ns;    }  tm = utc_option ? gmtime (&s) : localtime (&s);  if (tm)    {      if (full_time)	{	  sprintf (buffer, "%04ld-%02d-%02d %02d:%02d:%02d",		   tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,		   tm->tm_hour, tm->tm_min, tm->tm_sec);	  code_ns_fraction (ns, buffer + strlen (buffer));	}      else	sprintf (buffer, "%04ld-%02d-%02d %02d:%02d",		 tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,		 tm->tm_hour, tm->tm_min);      return buffer;    }  /* The time stamp cannot be broken down, most likely because it     is out of range.  Convert it as an integer,     right-adjusted in a field with the same width as the usual     4-year ISO time format.  */  p = umaxtostr (negative ? - (uintmax_t) s : s,		 buffer + sizeof buffer - UINTMAX_STRSIZE_BOUND - fraclen);  if (negative)    *--p = '-';  while ((buffer + sizeof buffer - sizeof "YYYY-MM-DD HH:MM"	  + (full_time ? sizeof ":SS.FFFFFFFFF" - 1 : 0))	 < p)    *--p = ' ';  if (full_time)    code_ns_fraction (ns, buffer + sizeof buffer - 1 - fraclen);  return p;}/* Actually print it.   Plain and fancy file header block logging.  Non-verbose just prints   the name, e.g. for "tar t" or "tar x".  This should just contain   file names, so it can be fed back into tar with xargs or the "-T"   option.  The verbose option can give a bunch of info, one line per   file.  I doubt anybody tries to parse its format, or if they do,   they shouldn't.  Unix tar is pretty random here anyway.  *//* FIXME: Note that print_header uses the globals HEAD, HSTAT, and   HEAD_STANDARD, which must be set up in advance.  Not very clean..  *//* Width of "user/group size", with initial value chosen   heuristically.  This grows as needed, though this may cause some   stairstepping in the output.  Make it too small and the output will   almost always look ragged.  Make it too large and the output will   be spaced out too far.  */static int ugswidth = 19;/* Width of printed time stamps.  It grows if longer time stamps are   found (typically, those with nanosecond resolution).  Like   USGWIDTH, some stairstepping may occur.  */static int datewidth = sizeof "YYYY-MM-DD HH:MM" - 1;voidprint_header (struct tar_stat_info *st, off_t block_ordinal){  char modes[11];  char const *time_stamp;  int time_stamp_len;  char *temp_name;  /* These hold formatted ints.  */  char uform[UINTMAX_STRSIZE_BOUND], gform[UINTMAX_STRSIZE_BOUND];  char *user, *group;  char size[2 * UINTMAX_STRSIZE_BOUND];  				/* holds formatted size or major,minor */  char uintbuf[UINTMAX_STRSIZE_BOUND];  int pad;  int sizelen;  if (test_label_option && current_header->header.typeflag != GNUTYPE_VOLHDR)    return;  if (show_transformed_names_option)    temp_name = st->file_name ? st->file_name : st->orig_file_name;  else    temp_name = st->orig_file_name ? st->orig_file_name : st->file_name;  if (block_number_option)    {      char buf[UINTMAX_STRSIZE_BOUND];      if (block_ordinal < 0)	block_ordinal = current_block_ordinal ();      block_ordinal -= recent_long_name_blocks;      block_ordinal -= recent_long_link_blocks;      fprintf (stdlis, _("block %s: "),	       STRINGIFY_BIGINT (block_ordinal, buf));    }  if (verbose_option <= 1)    {      /* Just the fax, mam.  */      fprintf (stdlis, "%s\n", quotearg (temp_name));    }  else    {      /* File type and modes.  */      modes[0] = '?';      switch (current_header->header.typeflag)	{	case GNUTYPE_VOLHDR:	  modes[0] = 'V';	  break;	case GNUTYPE_MULTIVOL:	  modes[0] = 'M';	  break;	case GNUTYPE_LONGNAME:	case GNUTYPE_LONGLINK:	  modes[0] = 'L';	  ERROR ((0, 0, _("Unexpected long name header")));	  break;	case GNUTYPE_SPARSE:	case REGTYPE:	case AREGTYPE:	  modes[0] = '-';	  if (temp_name[strlen (temp_name) - 1] == '/')	    modes[0] = 'd';	  break;	case LNKTYPE:	  modes[0] = 'h';	  break;	case GNUTYPE_DUMPDIR:	  modes[0] = 'd';	  break;	case DIRTYPE:	  modes[0] = 'd';	  break;	case SYMTYPE:	  modes[0] = 'l';	  break;	case BLKTYPE:	  modes[0] = 'b';	  break;	case CHRTYPE:	  modes[0] = 'c';	  break;	case FIFOTYPE:	  modes[0] = 'p';	  break;	case CONTTYPE:	  modes[0] = 'C';	  break;	}      pax_decode_mode (st->stat.st_mode, modes + 1);      /* Time stamp.  */      time_stamp = tartime (st->mtime, false);      time_stamp_len = strlen (time_stamp);      if (datewidth < time_stamp_len)	datewidth = time_stamp_len;      /* User and group names.  */      if (st->uname	  && st->uname[0]	  && current_format != V7_FORMAT	  && !numeric_owner_option)	user = st->uname;      else	{	  /* Try parsing it as an unsigned integer first, and as a	     uid_t if that fails.  This method can list positive user	     ids that are too large to fit in a uid_t.  */	  uintmax_t u = from_header (current_header->header.uid,				     sizeof current_header->header.uid, 0,				     (uintmax_t) 0,				     (uintmax_t) TYPE_MAXIMUM (uintmax_t),				     false, false);	  if (u != -1)	    user = STRINGIFY_BIGINT (u, uform);	  else	    {	      sprintf (uform, "%ld",		       (long) UID_FROM_HEADER (current_header->header.uid));	      user = uform;	    }	}      if (st->gname	  && st->gname[0]	  && current_format != V7_FORMAT	  && !numeric_owner_option)	group = st->gname;      else	{	  /* Try parsing it as an unsigned integer first, and as a	     gid_t if that fails.  This method can list positive group	     ids that are too large to fit in a gid_t.  */	  uintmax_t g = from_header (current_header->header.gid,				     sizeof current_header->header.gid, 0,				     (uintmax_t) 0,				     (uintmax_t) TYPE_MAXIMUM (uintmax_t),				     false, false);	  if (g != -1)	    group = STRINGIFY_BIGINT (g, gform);	  else	    {	      sprintf (gform, "%ld",		       (long) GID_FROM_HEADER (current_header->header.gid));	      group = gform;	    }	}      /* Format the file size or major/minor device numbers.  */      switch (current_header->header.typeflag)	{	case CHRTYPE:	case BLKTYPE:	  strcpy (size,		  STRINGIFY_BIGINT (major (st->stat.st_rdev), uintbuf));	  strcat (size, ",");	  strcat (size,		  STRINGIFY_BIGINT (minor (st->stat.st_rdev), uintbuf));	  break;	default:	  /* st->stat.st_size keeps stored file size */	  strcpy (size, STRINGIFY_BIGINT (st->stat.st_size, uintbuf));	  break;	}      /* Figure out padding and print the whole line.  */      sizelen = strlen (size);      pad = strlen (user) + 1 + strlen (group) + 1 + sizelen;      if (pad > ugswidth)	ugswidth = pad;      fprintf (stdlis, "%s %s/%s %*s %-*s",	       modes, user, group, ugswidth - pad + sizelen, size,	       datewidth, time_stamp);      fprintf (stdlis, " %s", quotearg (temp_name));      switch (current_header->header.typeflag)	{	case SYMTYPE:	  fprintf (stdlis, " -> %s\n", quotearg (st->link_name));	  break;	case LNKTYPE:	  fprintf (stdlis, _(" link to %s\n"), quotearg (st->link_name));	  break;	default:	  {	    char type_string[2];	    type_string[0] = current_header->header.typeflag;	    type_string[1] = '\0';	    fprintf (stdlis, _(" unknown file type %s\n"),		     quote (type_string));	  }	  break;	case AREGTYPE:	case REGTYPE:	case GNUTYPE_SPARSE:	case CHRTYPE:	case BLKTYPE:	case DIRTYPE:	case FIFOTYPE:	case CONTTYPE:	case GNUTYPE_DUMPDIR:	  putc ('\n', stdlis);	  break;	case GNUTYPE_LONGLINK:	  fprintf (stdlis, _("--Long Link--\n"));	  break;	case GNUTYPE_LONGNAME:	  fprintf (stdlis, _("--Long Name--\n"));	  break;	case GNUTYPE_VOLHDR:	  fprintf (stdlis, _("--Volume Header--\n"));	  break;	case GNUTYPE_MULTIVOL:	  strcpy (size,		  STRINGIFY_BIGINT		  (UINTMAX_FROM_HEADER (current_header->oldgnu_header.offset),		   uintbuf));	  fprintf (stdlis, _("--Continued at byte %s--\n"), size);	  break;	}    }  fflush (stdlis);}/* Print a similar line when we make a directory automatically.  */voidprint_for_mkdir (char *dirname, int length, mode_t mode){  char modes[11];  if (verbose_option > 1)    {      /* File type and modes.  */      modes[0] = 'd';      pax_decode_mode (mode, modes + 1);      if (block_number_option)	{	  char buf[UINTMAX_STRSIZE_BOUND];	  fprintf (stdlis, _("block %s: "),		   STRINGIFY_BIGINT (current_block_ordinal (), buf));	}      fprintf (stdlis, "%s %*s %.*s\n", modes, ugswidth + 1 + datewidth,	       _("Creating directory:"), length, quotearg (dirname));    }}/* Skip over SIZE bytes of data in blocks in the archive.  */voidskip_file (off_t size){  union block *x;  /* FIXME: Make sure mv_begin is always called before it */  if (seekable_archive)    {      off_t nblk = seek_archive (size);      if (nblk >= 0)	size -= nblk * BLOCKSIZE;      else	seekable_archive = false;    }  mv_size_left (size);  while (size > 0)    {      x = find_next_block ();      if (! x)	FATAL_ERROR ((0, 0, _("Unexpected EOF in archive")));      set_next_block_after (x);      size -= BLOCKSIZE;      mv_size_left (size);    }}/* Skip the current member in the archive.   NOTE: Current header must be decoded before calling this function. */voidskip_member (void){  if (!current_stat_info.skipped)    {      char save_typeflag = current_header->header.typeflag;      set_next_block_after (current_header);      mv_begin (&current_stat_info);      if (current_stat_info.is_sparse)	sparse_skip_file (&current_stat_info);      else if (save_typeflag != DIRTYPE)	skip_file (current_stat_info.stat.st_size);      mv_end ();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -