]> Dogcows Code - chaz/tar/blobdiff - src/list.c
indenting fixes
[chaz/tar] / src / list.c
index a06340d5e09044cfd39c73e7211546e072821b7d..1c245319cd57ff0c4147137eb38676d3d6a6a824 100644 (file)
@@ -386,7 +386,6 @@ read_header (void)
       else
        current_stat.st_size = OFF_FROM_CHARS (header->header.size);
 
-      header->header.name[NAME_FIELD_SIZE - 1] = '\0';
       if (header->header.typeflag == GNUTYPE_LONGNAME
          || header->header.typeflag == GNUTYPE_LONGLINK)
        {
@@ -425,16 +424,19 @@ read_header (void)
        }
       else
        {
-         char *name = next_long_name;
+         char *name;
          struct posix_header *h = &current_header->header;
-         char namebuf[sizeof h->prefix + 1 + sizeof h->name + 1];
+         char namebuf[sizeof h->prefix + 1 + NAME_FIELD_SIZE + 1];
 
+         name = next_long_name;
          if (! name)
            {
              /* Accept file names as specified by POSIX.1-1996
                  section 10.1.1.  */
+             int posix_header = strcmp (h->magic, TMAGIC) == 0;
              char *np = namebuf;
-             if (h->prefix[0])
+
+             if (posix_header && h->prefix[0])
                {
                  memcpy (np, h->prefix, sizeof h->prefix);
                  np[sizeof h->prefix] = '\0';
@@ -445,11 +447,17 @@ read_header (void)
              np[sizeof h->name] = '\0';
              name = namebuf;
            }
-
          assign_string (&current_file_name, name);
-         assign_string (&current_link_name,
-                        (next_long_link ? next_long_link
-                         : current_header->header.linkname));
+         
+         name = next_long_link;
+         if (! name)
+           {
+             memcpy (namebuf, h->linkname, sizeof h->linkname);
+             namebuf[sizeof h->linkname] = '\0';
+             name = namebuf;
+           }
+         assign_string (&current_link_name, name);
+
          next_long_link = next_long_name = 0;
          return HEADER_SUCCESS;
        }
@@ -744,13 +752,16 @@ stringify_uintmax_t_backwards (uintmax_t o, char *buf)
 static char *
 isotime (const time_t *time)
 {
-  static char buffer[21];
-  struct tm *tm;
+  static char buffer[INT_STRLEN_BOUND (int) + 16];
+  struct tm *tm = localtime (time);
+  if (tm)
+    sprintf (buffer, "%04d-%02d-%02d %02d:%02d:%02d",
+            tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+            tm->tm_hour, tm->tm_min, tm->tm_sec);
+  else
+    /* Interpose %s between ?? and - to avoid ANSI C trigraph brain damage.  */
+    sprintf (buffer, "????%s-??%s-?? ??:??:??", "", "");
 
-  tm = localtime (time);
-  sprintf (buffer, "%4d-%02d-%02d %02d:%02d:%02d\n",
-          tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
-          tm->tm_hour, tm->tm_min, tm->tm_sec);
   return buffer;
 }
 
@@ -812,7 +823,7 @@ void
 print_header (void)
 {
   char modes[11];
-  char *timestamp;
+  char const *timestamp;
   /* These hold formatted ints.  */
   char uform[UINTMAX_STRSIZE_BOUND], gform[UINTMAX_STRSIZE_BOUND];
   char *user, *group;
@@ -905,12 +916,20 @@ print_header (void)
 
       longie = current_stat.st_mtime;
 #if USE_OLD_CTIME
-      timestamp = ctime (&longie);
-      timestamp[16] = '\0';
-      timestamp[24] = '\0';
+      {
+       char *ct = ctime (&longie);
+       if (ct)
+         {
+           timestamp = ct + 4;
+           for (ct += 16; ct[4] != '\n'; ct++)
+             ct[0] = ct[4];
+           ct[0] = '\0';
+         }
+       else
+         timestamp = "??? ?? ??:?? ????";
+      }
 #else
       timestamp = isotime (&longie);
-      timestamp[16] = '\0';
 #endif
 
       /* User and group names.  */
@@ -958,14 +977,8 @@ print_header (void)
       if (pad > ugswidth)
        ugswidth = pad;
 
-#if USE_OLD_CTIME
-      fprintf (stdlis, "%s %s/%s %*s%s %s %s",
-              modes, user, group, ugswidth - pad, "",
-              size, timestamp + 4, timestamp + 20);
-#else
       fprintf (stdlis, "%s %s/%s %*s%s %s",
               modes, user, group, ugswidth - pad, "", size, timestamp);
-#endif
 
       name = quote_copy_string (current_file_name);
       if (name)
This page took 0.024834 seconds and 4 git commands to generate.