]> Dogcows Code - chaz/tar/blobdiff - src/xheader.c
tar: remove trailing white space from source files
[chaz/tar] / src / xheader.c
index 089604347ceab7c916b588a8e46172ceb760a7e9..311e7751f3579863d0ec86a3a5bcf1148be4f930 100644 (file)
@@ -1,10 +1,11 @@
 /* POSIX extended headers for tar.
 
-   Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software
+   Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 2, or (at your option) any later
+   Free Software Foundation; either version 3, or (at your option) any later
    version.
 
    This program is distributed in the hope that it will be useful, but
 #include <hash.h>
 #include <inttostr.h>
 #include <quotearg.h>
-#include <stpcpy.h>
 
 #include "common.h"
 
-#include <fnmatch.h>
-
 static bool xheader_protected_pattern_p (char const *pattern);
 static bool xheader_protected_keyword_p (char const *keyword);
 static void xheader_set_single_keyword (char *) __attribute__ ((noreturn));
@@ -35,7 +33,6 @@ static void xheader_set_single_keyword (char *) __attribute__ ((noreturn));
 /* Used by xheader_finish() */
 static void code_string (char const *string, char const *keyword,
                         struct xheader *xhdr);
-static void extended_header_init (void);
 
 /* Number of global headers written so far. */
 static size_t global_header_count;
@@ -100,9 +97,15 @@ static struct keyword_list *global_header_override_list;
 /* Template for the name field of an 'x' type header */
 static char *exthdr_name;
 
+static char *exthdr_mtime_option;
+static time_t exthdr_mtime;
+
 /* Template for the name field of a 'g' type header */
 static char *globexthdr_name;
 
+static char *globexthdr_mtime_option;
+static time_t globexthdr_mtime;
+
 bool
 xheader_keyword_deleted_p (const char *kw)
 {
@@ -160,6 +163,21 @@ xheader_set_single_keyword (char *kw)
   USAGE_ERROR ((0, 0, _("Keyword %s is unknown or not yet implemented"), kw));
 }
 
+static void
+assign_time_option (char **sval, time_t *tval, const char *input)
+{
+  uintmax_t u;
+  char *p;
+  time_t t = u = strtoumax (input, &p, 10);
+  if (t != u || *p || errno == ERANGE)
+    ERROR ((0, 0, _("Time stamp is out of allowed range")));
+  else
+    {
+      *tval = t;
+      assign_string (sval, input);
+    }
+}
+
 static void
 xheader_set_keyword_equal (char *kw, char *eq)
 {
@@ -172,12 +190,12 @@ xheader_set_keyword_equal (char *kw, char *eq)
       global = false;
     }
 
-  while (p > kw && isspace (*p))
+  while (p > kw && isspace ((unsigned char) *p))
     p--;
 
   *p = 0;
 
-  for (p = eq + 1; *p && isspace (*p); p++)
+  for (p = eq + 1; *p && isspace ((unsigned char) *p); p++)
     ;
 
   if (strcmp (kw, "delete") == 0)
@@ -190,6 +208,10 @@ xheader_set_keyword_equal (char *kw, char *eq)
     assign_string (&exthdr_name, p);
   else if (strcmp (kw, "globexthdr.name") == 0)
     assign_string (&globexthdr_name, p);
+  else if (strcmp (kw, "exthdr.mtime") == 0)
+    assign_time_option (&exthdr_mtime_option, &exthdr_mtime, p);
+  else if (strcmp (kw, "globexthdr.mtime") == 0)
+    assign_time_option (&globexthdr_mtime_option, &globexthdr_mtime, p);
   else
     {
       if (xheader_protected_keyword_p (kw))
@@ -225,7 +247,7 @@ xheader_set_option (char *string)
                               to the result of the basename
                               utility on the translated file name.
      %p                       The process ID of the pax process.
-     %n                       The value of the 3rd argument.  
+     %n                       The value of the 3rd argument.
      %%                       A '%' character. */
 
 char *
@@ -264,7 +286,7 @@ xheader_format_name (struct tar_stat_info *st, const char *fmt, size_t n)
        case 'f':
          if (st)
            {
-             base = base_name (st->orig_file_name);
+             base = last_component (st->orig_file_name);
              len += strlen (base) - 2;
            }
          break;
@@ -331,7 +353,7 @@ xheader_format_name (struct tar_stat_info *st, const char *fmt, size_t n)
     }
 
   free (dirp);
-  
+
   /* Do not allow it to end in a slash */
   while (q > buf && ISSLASH (q[-1]))
     q--;
@@ -368,14 +390,26 @@ xheader_ghdr_name (void)
 }
 
 void
-xheader_write (char type, char *name, struct xheader *xhdr)
+xheader_write (char type, char *name, time_t t, struct xheader *xhdr)
 {
   union block *header;
   size_t size;
   char *p;
 
   size = xhdr->size;
-  header = start_private_header (name, size);
+  switch (type)
+    {
+    case XGLTYPE:
+      if (globexthdr_mtime_option)
+       t = globexthdr_mtime;
+      break;
+
+    case XHDTYPE:
+      if (exthdr_mtime_option)
+       t = exthdr_mtime;
+      break;
+    }
+  header = start_private_header (name, size, t);
   header->header.typeflag = type;
 
   simple_finish_header (header);
@@ -405,33 +439,39 @@ xheader_write (char type, char *name, struct xheader *xhdr)
 }
 
 void
-xheader_write_global (void)
+xheader_write_global (struct xheader *xhdr)
 {
-  char *name;
-  struct keyword_list *kp;
+  if (keyword_global_override_list)
+    {
+      struct keyword_list *kp;
 
-  if (!keyword_global_override_list)
-    return;
+      xheader_init (xhdr);
+      for (kp = keyword_global_override_list; kp; kp = kp->next)
+       code_string (kp->value, kp->pattern, xhdr);
+    }
+  if (xhdr->stk)
+    {
+      char *name;
 
-  extended_header_init ();
-  for (kp = keyword_global_override_list; kp; kp = kp->next)
-    code_string (kp->value, kp->pattern, &extended_header);
-  xheader_finish (&extended_header);
-  xheader_write (XGLTYPE, name = xheader_ghdr_name (),
-                &extended_header);
-  free (name);
+      xheader_finish (xhdr);
+      xheader_write (XGLTYPE, name = xheader_ghdr_name (), time (NULL), xhdr);
+      free (name);
+    }
 }
 
 \f
 /* General Interface */
 
+#define XHDR_PROTECTED 0x01
+#define XHDR_GLOBAL    0x02
+
 struct xhdr_tab
 {
   char const *keyword;
   void (*coder) (struct tar_stat_info const *, char const *,
                 struct xheader *, void const *data);
-  void (*decoder) (struct tar_stat_info *, char const *, size_t);
-  bool protect;
+  void (*decoder) (struct tar_stat_info *, char const *, char const *, size_t);
+  int flags;
 };
 
 /* This declaration must be extern, because ISO C99 section 6.9.2
@@ -459,7 +499,7 @@ xheader_protected_pattern_p (const char *pattern)
   struct xhdr_tab const *p;
 
   for (p = xhdr_tab; p->keyword; p++)
-    if (p->protect && fnmatch (pattern, p->keyword, 0) == 0)
+    if ((p->flags & XHDR_PROTECTED) && fnmatch (pattern, p->keyword, 0) == 0)
       return true;
   return false;
 }
@@ -470,7 +510,7 @@ xheader_protected_keyword_p (const char *keyword)
   struct xhdr_tab const *p;
 
   for (p = xhdr_tab; p->keyword; p++)
-    if (p->protect && strcmp (p->keyword, keyword) == 0)
+    if ((p->flags & XHDR_PROTECTED) && strcmp (p->keyword, keyword) == 0)
       return true;
   return false;
 }
@@ -478,17 +518,19 @@ xheader_protected_keyword_p (const char *keyword)
 /* Decode a single extended header record, advancing *PTR to the next record.
    Return true on success, false otherwise.  */
 static bool
-decode_record (char **ptr,
+decode_record (struct xheader *xhdr,
+              char **ptr,
               void (*handler) (void *, char const *, char const *, size_t),
               void *data)
 {
   char *start = *ptr;
   char *p = start;
-  unsigned long int len;
+  uintmax_t u;
+  size_t len;
   char *len_lim;
   char const *keyword;
   char *nextp;
-  size_t len_max = extended_header.buffer + extended_header.size - start;
+  size_t len_max = xhdr->buffer + xhdr->size - start;
 
   while (*p == ' ' || *p == '\t')
     p++;
@@ -501,7 +543,12 @@ decode_record (char **ptr,
     }
 
   errno = 0;
-  len = strtoul (p, &len_lim, 10);
+  len = u = strtoumax (p, &len_lim, 10);
+  if (len != u || errno == ERANGE)
+    {
+      ERROR ((0, 0, _("Extended header length is out of allowed range")));
+      return false;
+    }
 
   if (len_max < len)
     {
@@ -551,7 +598,7 @@ run_override_list (struct keyword_list *kp, struct tar_stat_info *st)
     {
       struct xhdr_tab const *t = locate_handler (kp->pattern);
       if (t)
-       t->decoder (st, kp->value, strlen (kp->value));
+       t->decoder (st, t->keyword, kp->value, strlen (kp->value));
     }
 }
 
@@ -567,10 +614,11 @@ decx (void *data, char const *keyword, char const *value, size_t size)
 
   t = locate_handler (keyword);
   if (t)
-    t->decoder (st, value, size);
+    t->decoder (st, keyword, value, size);
   else
-    ERROR((0, 0, _("Ignoring unknown extended header keyword `%s'"),
-          keyword));
+    WARNOPT (WARN_UNKNOWN_KEYWORD,
+            (0, 0, _("Ignoring unknown extended header keyword `%s'"),
+             keyword));
 }
 
 void
@@ -579,10 +627,10 @@ xheader_decode (struct tar_stat_info *st)
   run_override_list (keyword_global_override_list, st);
   run_override_list (global_header_override_list, st);
 
-  if (extended_header.size)
+  if (st->xhdr.size)
     {
-      char *p = extended_header.buffer + BLOCKSIZE;
-      while (decode_record (&p, decx, st))
+      char *p = st->xhdr.buffer + BLOCKSIZE;
+      while (decode_record (&st->xhdr, &p, decx, st))
        continue;
     }
   run_override_list (keyword_override_list, st);
@@ -593,39 +641,43 @@ decg (void *data, char const *keyword, char const *value,
       size_t size __attribute__((unused)))
 {
   struct keyword_list **kwl = data;
-  xheader_list_append (kwl, keyword, value);
+  struct xhdr_tab const *tab = locate_handler (keyword);
+  if (tab && (tab->flags & XHDR_GLOBAL))
+    tab->decoder (data, keyword, value, size);
+  else
+    xheader_list_append (kwl, keyword, value);
 }
 
 void
-xheader_decode_global (void)
+xheader_decode_global (struct xheader *xhdr)
 {
-  if (extended_header.size)
+  if (xhdr->size)
     {
-      char *p = extended_header.buffer + BLOCKSIZE;
+      char *p = xhdr->buffer + BLOCKSIZE;
 
       xheader_list_destroy (&global_header_override_list);
-      while (decode_record (&p, decg, &global_header_override_list))
+      while (decode_record (xhdr, &p, decg, &global_header_override_list))
        continue;
     }
 }
 
-static void
-extended_header_init (void)
+void
+xheader_init (struct xheader *xhdr)
 {
-  if (!extended_header.stk)
+  if (!xhdr->stk)
     {
-      extended_header.stk = xmalloc (sizeof *extended_header.stk);
-      obstack_init (extended_header.stk);
+      xhdr->stk = xmalloc (sizeof *xhdr->stk);
+      obstack_init (xhdr->stk);
     }
 }
 
 void
-xheader_store (char const *keyword, struct tar_stat_info const *st,
+xheader_store (char const *keyword, struct tar_stat_info *st,
               void const *data)
 {
   struct xhdr_tab const *t;
 
-  if (extended_header.buffer)
+  if (st->xhdr.buffer)
     return;
   t = locate_handler (keyword);
   if (!t || !t->coder)
@@ -633,22 +685,19 @@ xheader_store (char const *keyword, struct tar_stat_info const *st,
   if (xheader_keyword_deleted_p (keyword)
       || xheader_keyword_override_p (keyword))
     return;
-  extended_header_init ();
-  t->coder (st, keyword, &extended_header, data);
+  xheader_init (&st->xhdr);
+  t->coder (st, keyword, &st->xhdr, data);
 }
 
 void
-xheader_read (union block *p, size_t size)
+xheader_read (struct xheader *xhdr, union block *p, size_t size)
 {
   size_t j = 0;
-  size_t nblocks;
 
-  free (extended_header.buffer);
   size += BLOCKSIZE;
-  extended_header.size = size;
-  nblocks = (size + BLOCKSIZE - 1) / BLOCKSIZE;
-  extended_header.buffer = xmalloc (size + 1);
-  extended_header.buffer[size] = '\0';
+  xhdr->size = size;
+  xhdr->buffer = xmalloc (size + 1);
+  xhdr->buffer[size] = '\0';
 
   do
     {
@@ -657,7 +706,10 @@ xheader_read (union block *p, size_t size)
       if (len > BLOCKSIZE)
        len = BLOCKSIZE;
 
-      memcpy (&extended_header.buffer[j], p->buffer, len);
+      if (!p)
+       FATAL_ERROR ((0, 0, _("Unexpected EOF in archive")));
+
+      memcpy (&xhdr->buffer[j], p->buffer, len);
       set_next_block_after (p);
 
       p = find_next_block ();
@@ -728,39 +780,39 @@ xheader_destroy (struct xheader *xhdr)
 
 \f
 /* Buildable strings */
-static uintmax_t string_length;
 
 void
-xheader_string_begin ()
+xheader_string_begin (struct xheader *xhdr)
 {
-  string_length = 0;
+  xhdr->string_length = 0;
 }
 
 void
-xheader_string_add (char const *s)
+xheader_string_add (struct xheader *xhdr, char const *s)
 {
-  if (extended_header.buffer)
+  if (xhdr->buffer)
     return;
-  extended_header_init ();
-  string_length += strlen (s);
-  x_obstack_grow (&extended_header, s, strlen (s));
+  xheader_init (xhdr);
+  xhdr->string_length += strlen (s);
+  x_obstack_grow (xhdr, s, strlen (s));
 }
 
-void
-xheader_string_end (char const *keyword)
+bool
+xheader_string_end (struct xheader *xhdr, char const *keyword)
 {
-  size_t len;
-  size_t p;
-  size_t n = 0;
+  uintmax_t len;
+  uintmax_t p;
+  uintmax_t n = 0;
+  size_t size;
   char nbuf[UINTMAX_STRSIZE_BOUND];
   char const *np;
   char *cp;
 
-  if (extended_header.buffer)
-    return;
-  extended_header_init ();
+  if (xhdr->buffer)
+    return false;
+  xheader_init (xhdr);
 
-  len = strlen (keyword) + string_length + 3; /* ' ' + '=' + '\n' */
+  len = strlen (keyword) + xhdr->string_length + 3; /* ' ' + '=' + '\n' */
 
   do
     {
@@ -771,14 +823,24 @@ xheader_string_end (char const *keyword)
   while (n != p);
 
   p = strlen (keyword) + n + 2;
-  x_obstack_blank (&extended_header, p);
-  x_obstack_1grow (&extended_header, '\n');
-  cp = obstack_next_free (extended_header.stk) - string_length - p - 1;
-  memmove (cp + p, cp, string_length);
+  size = p;
+  if (size != p)
+    {
+      ERROR ((0, 0,
+        _("Generated keyword/value pair is too long (keyword=%s, length=%s)"),
+             keyword, nbuf));
+      obstack_free (xhdr->stk, obstack_finish (xhdr->stk));
+      return false;
+    }
+  x_obstack_blank (xhdr, p);
+  x_obstack_1grow (xhdr, '\n');
+  cp = obstack_next_free (xhdr->stk) - xhdr->string_length - p - 1;
+  memmove (cp + p, cp, xhdr->string_length);
   cp = stpcpy (cp, np);
   *cp++ = ' ';
   cp = stpcpy (cp, keyword);
   *cp++ = '=';
+  return true;
 }
 
 \f
@@ -939,7 +1001,7 @@ decode_time (struct timespec *ts, char const *arg, char const *keyword)
   return true;
 }
 
-  
+
 
 static void
 code_num (uintmax_t value, char const *keyword, struct xheader *xhdr)
@@ -983,6 +1045,7 @@ dummy_coder (struct tar_stat_info const *st __attribute__ ((unused)),
 
 static void
 dummy_decoder (struct tar_stat_info *st __attribute__ ((unused)),
+              char const *keyword __attribute__ ((unused)),
               char const *arg __attribute__ ((unused)),
               size_t size __attribute__((unused)))
 {
@@ -996,11 +1059,13 @@ atime_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-atime_decoder (struct tar_stat_info *st, char const *arg,
+atime_decoder (struct tar_stat_info *st,
+              char const *keyword,
+              char const *arg,
               size_t size __attribute__((unused)))
 {
   struct timespec ts;
-  if (decode_time (&ts, arg, "atime"))
+  if (decode_time (&ts, arg, keyword))
     st->atime = ts;
 }
 
@@ -1012,11 +1077,13 @@ gid_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-gid_decoder (struct tar_stat_info *st, char const *arg,
+gid_decoder (struct tar_stat_info *st,
+            char const *keyword,
+            char const *arg,
             size_t size __attribute__((unused)))
 {
   uintmax_t u;
-  if (decode_num (&u, arg, TYPE_MAXIMUM (gid_t), "gid"))
+  if (decode_num (&u, arg, TYPE_MAXIMUM (gid_t), keyword))
     st->stat.st_gid = u;
 }
 
@@ -1028,7 +1095,9 @@ gname_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-gname_decoder (struct tar_stat_info *st, char const *arg,
+gname_decoder (struct tar_stat_info *st,
+              char const *keyword __attribute__((unused)),
+              char const *arg,
               size_t size __attribute__((unused)))
 {
   decode_string (&st->gname, arg);
@@ -1042,7 +1111,9 @@ linkpath_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-linkpath_decoder (struct tar_stat_info *st, char const *arg,
+linkpath_decoder (struct tar_stat_info *st,
+                 char const *keyword __attribute__((unused)),
+                 char const *arg,
                  size_t size __attribute__((unused)))
 {
   decode_string (&st->link_name, arg);
@@ -1056,27 +1127,32 @@ ctime_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-ctime_decoder (struct tar_stat_info *st, char const *arg,
+ctime_decoder (struct tar_stat_info *st,
+              char const *keyword,
+              char const *arg,
               size_t size __attribute__((unused)))
 {
   struct timespec ts;
-  if (decode_time (&ts, arg, "ctime"))
+  if (decode_time (&ts, arg, keyword))
     st->ctime = ts;
 }
 
 static void
 mtime_coder (struct tar_stat_info const *st, char const *keyword,
-            struct xheader *xhdr, void const *data __attribute__ ((unused)))
+            struct xheader *xhdr, void const *data)
 {
-  code_time (st->mtime, keyword, xhdr);
+  struct timespec const *mtime = data;
+  code_time (mtime ? *mtime : st->mtime, keyword, xhdr);
 }
 
 static void
-mtime_decoder (struct tar_stat_info *st, char const *arg,
+mtime_decoder (struct tar_stat_info *st,
+              char const *keyword,
+              char const *arg,
               size_t size __attribute__((unused)))
 {
   struct timespec ts;
-  if (decode_time (&ts, arg, "mtime"))
+  if (decode_time (&ts, arg, keyword))
     st->mtime = ts;
 }
 
@@ -1088,7 +1164,9 @@ path_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-path_decoder (struct tar_stat_info *st, char const *arg,
+path_decoder (struct tar_stat_info *st,
+             char const *keyword __attribute__((unused)),
+             char const *arg,
              size_t size __attribute__((unused)))
 {
   decode_string (&st->orig_file_name, arg);
@@ -1104,11 +1182,13 @@ size_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-size_decoder (struct tar_stat_info *st, char const *arg,
+size_decoder (struct tar_stat_info *st,
+             char const *keyword,
+             char const *arg,
              size_t size __attribute__((unused)))
 {
   uintmax_t u;
-  if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), "size"))
+  if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), keyword))
     st->stat.st_size = u;
 }
 
@@ -1120,11 +1200,13 @@ uid_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-uid_decoder (struct tar_stat_info *st, char const *arg,
+uid_decoder (struct tar_stat_info *st,
+            char const *keyword,
+            char const *arg,
             size_t size __attribute__((unused)))
 {
   uintmax_t u;
-  if (decode_num (&u, arg, TYPE_MAXIMUM (uid_t), "uid"))
+  if (decode_num (&u, arg, TYPE_MAXIMUM (uid_t), keyword))
     st->stat.st_uid = u;
 }
 
@@ -1136,7 +1218,9 @@ uname_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-uname_decoder (struct tar_stat_info *st, char const *arg,
+uname_decoder (struct tar_stat_info *st,
+              char const *keyword __attribute__((unused)),
+              char const *arg,
               size_t size __attribute__((unused)))
 {
   decode_string (&st->uname, arg);
@@ -1150,11 +1234,13 @@ sparse_size_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-sparse_size_decoder (struct tar_stat_info *st, char const *arg,
+sparse_size_decoder (struct tar_stat_info *st,
+                    char const *keyword,
+                    char const *arg,
                     size_t size __attribute__((unused)))
 {
   uintmax_t u;
-  if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), "GNU.sparse.size"))
+  if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), keyword))
     st->stat.st_size = u;
 }
 
@@ -1167,11 +1253,13 @@ sparse_numblocks_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-sparse_numblocks_decoder (struct tar_stat_info *st, char const *arg,
+sparse_numblocks_decoder (struct tar_stat_info *st,
+                         char const *keyword,
+                         char const *arg,
                          size_t size __attribute__((unused)))
 {
   uintmax_t u;
-  if (decode_num (&u, arg, SIZE_MAX, "GNU.sparse.numblocks"))
+  if (decode_num (&u, arg, SIZE_MAX, keyword))
     {
       st->sparse_map_size = u;
       st->sparse_map = xcalloc (u, sizeof st->sparse_map[0]);
@@ -1188,11 +1276,13 @@ sparse_offset_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-sparse_offset_decoder (struct tar_stat_info *st, char const *arg,
+sparse_offset_decoder (struct tar_stat_info *st,
+                      char const *keyword,
+                      char const *arg,
                       size_t size __attribute__((unused)))
 {
   uintmax_t u;
-  if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), "GNU.sparse.offset"))
+  if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), keyword))
     {
       if (st->sparse_map_avail < st->sparse_map_size)
        st->sparse_map[st->sparse_map_avail].offset = u;
@@ -1211,26 +1301,29 @@ sparse_numbytes_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-sparse_numbytes_decoder (struct tar_stat_info *st, char const *arg,
+sparse_numbytes_decoder (struct tar_stat_info *st,
+                        char const *keyword,
+                        char const *arg,
                         size_t size __attribute__((unused)))
 {
   uintmax_t u;
-  if (decode_num (&u, arg, SIZE_MAX, "GNU.sparse.numbytes"))
+  if (decode_num (&u, arg, SIZE_MAX, keyword))
     {
       if (st->sparse_map_avail < st->sparse_map_size)
        st->sparse_map[st->sparse_map_avail++].numbytes = u;
       else
        ERROR ((0, 0, _("Malformed extended header: excess %s=%s"),
-               "GNU.sparse.numbytes", arg));
+               keyword, arg));
     }
 }
 
 static void
-sparse_map_decoder (struct tar_stat_info *st, char const *arg,
+sparse_map_decoder (struct tar_stat_info *st,
+                   char const *keyword,
+                   char const *arg,
                    size_t size __attribute__((unused)))
 {
   int offset = 1;
-  static char *keyword = "GNU.sparse.map";
 
   st->sparse_map_avail = 0;
   while (1)
@@ -1304,7 +1397,9 @@ dumpdir_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-dumpdir_decoder (struct tar_stat_info *st, char const *arg,
+dumpdir_decoder (struct tar_stat_info *st,
+                char const *keyword __attribute__((unused)),
+                char const *arg,
                 size_t size)
 {
   st->dumpdir = xmalloc (size);
@@ -1319,7 +1414,10 @@ volume_label_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-volume_label_decoder (struct tar_stat_info *st, char const *arg, size_t size)
+volume_label_decoder (struct tar_stat_info *st,
+                     char const *keyword __attribute__((unused)),
+                     char const *arg,
+                     size_t size __attribute__((unused)))
 {
   decode_string (&volume_label, arg);
 }
@@ -1328,15 +1426,17 @@ static void
 volume_size_coder (struct tar_stat_info const *st, char const *keyword,
                   struct xheader *xhdr, void const *data)
 {
-  off_t v = *(off_t*)data;
-  code_num (v, keyword, xhdr);
+  off_t const *v = data;
+  code_num (*v, keyword, xhdr);
 }
 
 static void
-volume_size_decoder (struct tar_stat_info *st, char const *arg, size_t size)
+volume_size_decoder (struct tar_stat_info *st,
+                    char const *keyword,
+                    char const *arg, size_t size)
 {
   uintmax_t u;
-  if (decode_num (&u, arg, TYPE_MAXIMUM (uintmax_t), "GNU.volume.size"))
+  if (decode_num (&u, arg, TYPE_MAXIMUM (uintmax_t), keyword))
     continued_file_size = u;
 }
 
@@ -1345,21 +1445,25 @@ static void
 volume_offset_coder (struct tar_stat_info const *st, char const *keyword,
                     struct xheader *xhdr, void const *data)
 {
-  off_t v = *(off_t*)data;
-  code_num (v, keyword, xhdr);
+  off_t const *v = data;
+  code_num (*v, keyword, xhdr);
 }
 
 static void
-volume_offset_decoder (struct tar_stat_info *st, char const *arg, size_t size)
+volume_offset_decoder (struct tar_stat_info *st,
+                      char const *keyword,
+                      char const *arg, size_t size)
 {
   uintmax_t u;
-  if (decode_num (&u, arg, TYPE_MAXIMUM (uintmax_t), "GNU.volume.offset"))
+  if (decode_num (&u, arg, TYPE_MAXIMUM (uintmax_t), keyword))
     continued_file_offset = u;
 }
 
 static void
-volume_filename_decoder (struct tar_stat_info *st, char const *arg,
-                        size_t size)
+volume_filename_decoder (struct tar_stat_info *st,
+                        char const *keyword __attribute__((unused)),
+                        char const *arg,
+                        size_t size __attribute__((unused)))
 {
   decode_string (&continued_file_name, arg);
 }
@@ -1372,74 +1476,82 @@ sparse_major_coder (struct tar_stat_info const *st, char const *keyword,
 }
 
 static void
-sparse_major_decoder (struct tar_stat_info *st, char const *arg,
+sparse_major_decoder (struct tar_stat_info *st,
+                     char const *keyword,
+                     char const *arg,
                      size_t size)
 {
   uintmax_t u;
-  if (decode_num (&u, arg, TYPE_MAXIMUM (unsigned), "GNU.sparse.major"))
+  if (decode_num (&u, arg, TYPE_MAXIMUM (unsigned), keyword))
     st->sparse_major = u;
 }
-  
+
 static void
 sparse_minor_coder (struct tar_stat_info const *st, char const *keyword,
                      struct xheader *xhdr, void const *data)
 {
-  code_num (st->sparse_minor, keyword, xhdr); 
+  code_num (st->sparse_minor, keyword, xhdr);
 }
 
 static void
-sparse_minor_decoder (struct tar_stat_info *st, char const *arg,
+sparse_minor_decoder (struct tar_stat_info *st,
+                     char const *keyword,
+                     char const *arg,
                      size_t size)
 {
   uintmax_t u;
-  if (decode_num (&u, arg, TYPE_MAXIMUM (unsigned), "GNU.sparse.minor"))
+  if (decode_num (&u, arg, TYPE_MAXIMUM (unsigned), keyword))
     st->sparse_minor = u;
 }
-  
+
 struct xhdr_tab const xhdr_tab[] = {
-  { "atime",   atime_coder,    atime_decoder,    false },
-  { "comment", dummy_coder,    dummy_decoder,    false },
-  { "charset", dummy_coder,    dummy_decoder,    false },
-  { "ctime",   ctime_coder,    ctime_decoder,    false },
-  { "gid",     gid_coder,      gid_decoder,      false },
-  { "gname",   gname_coder,    gname_decoder,    false },
-  { "linkpath", linkpath_coder, linkpath_decoder, false },
-  { "mtime",   mtime_coder,    mtime_decoder,    false },
-  { "path",    path_coder,     path_decoder,     false },
-  { "size",    size_coder,     size_decoder,     false },
-  { "uid",     uid_coder,      uid_decoder,      false },
-  { "uname",   uname_coder,    uname_decoder,    false },
+  { "atime",   atime_coder,    atime_decoder,    0 },
+  { "comment", dummy_coder,    dummy_decoder,    0 },
+  { "charset", dummy_coder,    dummy_decoder,    0 },
+  { "ctime",   ctime_coder,    ctime_decoder,    0 },
+  { "gid",     gid_coder,      gid_decoder,      0 },
+  { "gname",   gname_coder,    gname_decoder,    0 },
+  { "linkpath", linkpath_coder, linkpath_decoder, 0 },
+  { "mtime",   mtime_coder,    mtime_decoder,    0 },
+  { "path",    path_coder,     path_decoder,     0 },
+  { "size",    size_coder,     size_decoder,     0 },
+  { "uid",     uid_coder,      uid_decoder,      0 },
+  { "uname",   uname_coder,    uname_decoder,    0 },
 
   /* Sparse file handling */
   { "GNU.sparse.name",       path_coder, path_decoder,
-    true },
+    XHDR_PROTECTED },
   { "GNU.sparse.major",      sparse_major_coder, sparse_major_decoder,
-    true },
+    XHDR_PROTECTED },
   { "GNU.sparse.minor",      sparse_minor_coder, sparse_minor_decoder,
-    true },
-  { "GNU.sparse.realsize",  sparse_size_coder, sparse_size_decoder, true },
-  
-  { "GNU.sparse.size",       sparse_size_coder, sparse_size_decoder, true },
+    XHDR_PROTECTED },
+  { "GNU.sparse.realsize",   sparse_size_coder, sparse_size_decoder,
+    XHDR_PROTECTED },
   { "GNU.sparse.numblocks",  sparse_numblocks_coder, sparse_numblocks_decoder,
-    true },
+    XHDR_PROTECTED },
+
+  /* tar 1.14 - 1.15.90 keywords. */
+  { "GNU.sparse.size",       sparse_size_coder, sparse_size_decoder,
+    XHDR_PROTECTED },
   /* tar 1.14 - 1.15.1 keywords. Multiple instances of these appeared in 'x'
      headers, and each of them was meaningful. It confilcted with POSIX specs,
      which requires that "when extended header records conflict, the last one
      given in the header shall take precedence." */
   { "GNU.sparse.offset",     sparse_offset_coder, sparse_offset_decoder,
-    true },
+    XHDR_PROTECTED },
   { "GNU.sparse.numbytes",   sparse_numbytes_coder, sparse_numbytes_decoder,
-    true },
+    XHDR_PROTECTED },
   /* tar 1.15.90 keyword, introduced to remove the above-mentioned conflict. */
   { "GNU.sparse.map",        NULL /* Unused, see pax_dump_header() */,
-    sparse_map_decoder, false },
+    sparse_map_decoder, 0 },
 
   { "GNU.dumpdir",           dumpdir_coder, dumpdir_decoder,
-    true },
+    XHDR_PROTECTED },
 
   /* Keeps the tape/volume label. May be present only in the global headers.
      Equivalent to GNUTYPE_VOLHDR.  */
-  { "GNU.volume.label", volume_label_coder, volume_label_decoder, true },
+  { "GNU.volume.label", volume_label_coder, volume_label_decoder,
+    XHDR_PROTECTED | XHDR_GLOBAL },
 
   /* These may be present in a first global header of the archive.
      They provide the same functionality as GNUTYPE_MULTIVOL header.
@@ -1448,9 +1560,11 @@ struct xhdr_tab const xhdr_tab[] = {
      GNU.volume.offset keeps the offset of the start of this volume,
      otherwise kept in oldgnu_header.offset.  */
   { "GNU.volume.filename", volume_label_coder, volume_filename_decoder,
-    true },
-  { "GNU.volume.size", volume_size_coder, volume_size_decoder, true },
-  { "GNU.volume.offset", volume_offset_coder, volume_offset_decoder, true },
+    XHDR_PROTECTED | XHDR_GLOBAL },
+  { "GNU.volume.size", volume_size_coder, volume_size_decoder,
+    XHDR_PROTECTED | XHDR_GLOBAL },
+  { "GNU.volume.offset", volume_offset_coder, volume_offset_decoder,
+    XHDR_PROTECTED | XHDR_GLOBAL },
 
-  { NULL, NULL, NULL, false }
+  { NULL, NULL, NULL, 0 }
 };
This page took 0.045335 seconds and 4 git commands to generate.