]> Dogcows Code - chaz/tar/blobdiff - src/xheader.c
* src/xheader.c (strtoimax, strtoumax): Remove decls; now done
[chaz/tar] / src / xheader.c
index e88934e85ec82823e8b6ee1ebcf55338b3feba46..b8d4bfb7a7c80f40b128657eff39cb0d79554337 100644 (file)
 
 #include <fnmatch.h>
 
-#if !HAVE_DECL_STRTOIMAX && !defined strtoimax
-intmax_t strtoimax ();
-#endif
-#if !HAVE_DECL_STRTOUMAX && !defined strtoumax
-uintmax_t strtoumax ();
-#endif
-
 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));
@@ -57,8 +50,6 @@ static size_t global_header_count;
 
    However it should wait until buffer.c is finally rewritten */
 
-enum { BILLION = 1000000000, LOG10_BILLION = 9 };
-
 \f
 /* Keyword options */
 
@@ -747,23 +738,8 @@ decode_string (char **string, char const *arg)
 static void
 code_time (struct timespec t, char const *keyword, struct xheader *xhdr)
 {
-  time_t s = t.tv_sec;
-  int ns = t.tv_nsec;
-  char sbuf[1/*"-"*/ + UINTMAX_STRSIZE_BOUND + 1/*"."*/ + LOG10_BILLION];
-  char *np;
-  bool negative = s < 0;
-
-  if (negative && ns != 0)
-    {
-      s++;
-      ns = BILLION - ns;
-    }
-
-  np = umaxtostr (negative ? - (uintmax_t) s : (uintmax_t) s, sbuf + 1);
-  if (negative)
-    *--np = '-';
-  code_ns_fraction (ns, sbuf + UINTMAX_STRSIZE_BOUND);
-  xheader_print (xhdr, keyword, np);
+  char buf[TIMESPEC_STRSIZE_BOUND];
+  xheader_print (xhdr, keyword, code_timespec (t, buf));
 }
 
 static bool
@@ -900,7 +876,7 @@ static void
 atime_coder (struct tar_stat_info const *st, char const *keyword,
             struct xheader *xhdr, void *data __attribute__ ((unused)))
 {
-  code_time (get_stat_atime (&st->stat), keyword, xhdr);
+  code_time (st->atime, keyword, xhdr);
 }
 
 static void
@@ -908,7 +884,7 @@ atime_decoder (struct tar_stat_info *st, char const *arg)
 {
   struct timespec ts;
   if (decode_time (&ts, arg, "atime"))
-    set_stat_atime (&st->stat, ts);
+    st->atime = ts;
 }
 
 static void
@@ -956,7 +932,7 @@ static void
 ctime_coder (struct tar_stat_info const *st, char const *keyword,
             struct xheader *xhdr, void *data __attribute__ ((unused)))
 {
-  code_time (get_stat_ctime (&st->stat), keyword, xhdr);
+  code_time (st->ctime, keyword, xhdr);
 }
 
 static void
@@ -964,14 +940,14 @@ ctime_decoder (struct tar_stat_info *st, char const *arg)
 {
   struct timespec ts;
   if (decode_time (&ts, arg, "ctime"))
-    set_stat_ctime (&st->stat, ts);
+    st->ctime = ts;
 }
 
 static void
 mtime_coder (struct tar_stat_info const *st, char const *keyword,
             struct xheader *xhdr, void *data __attribute__ ((unused)))
 {
-  code_time (get_stat_mtime (&st->stat), keyword, xhdr);
+  code_time (st->mtime, keyword, xhdr);
 }
 
 static void
@@ -979,7 +955,7 @@ mtime_decoder (struct tar_stat_info *st, char const *arg)
 {
   struct timespec ts;
   if (decode_time (&ts, arg, "mtime"))
-    set_stat_mtime (&st->stat, ts);
+    st->mtime = ts;
 }
 
 static void
@@ -1009,7 +985,7 @@ size_decoder (struct tar_stat_info *st, char const *arg)
 {
   uintmax_t u;
   if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), "size"))
-    st->archive_file_size = st->stat.st_size = u;
+    st->stat.st_size = u;
 }
 
 static void
@@ -1079,8 +1055,8 @@ static void
 sparse_offset_coder (struct tar_stat_info const *st, char const *keyword,
                     struct xheader *xhdr, void *data)
 {
-  size_t i = *(size_t*)data;
-  code_num (st->sparse_map[i].offset, keyword, xhdr);
+  size_t *pi = data;
+  code_num (st->sparse_map[*pi].offset, keyword, xhdr);
 }
 
 static void
@@ -1088,15 +1064,21 @@ sparse_offset_decoder (struct tar_stat_info *st, char const *arg)
 {
   uintmax_t u;
   if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), "GNU.sparse.offset"))
-    st->sparse_map[st->sparse_map_avail].offset = u;
+    {
+      if (st->sparse_map_avail < st->sparse_map_size)
+       st->sparse_map[st->sparse_map_avail].offset = u;
+      else
+       ERROR ((0, 0, _("Malformed extended header: excess %s=%s"),
+               "GNU.sparse.offset", arg));
+    }
 }
 
 static void
 sparse_numbytes_coder (struct tar_stat_info const *st, char const *keyword,
                     struct xheader *xhdr, void *data)
 {
-  size_t i = *(size_t*)data;
-  code_num (st->sparse_map[i].numbytes, keyword, xhdr);
+  size_t *pi = data;
+  code_num (st->sparse_map[*pi].numbytes, keyword, xhdr);
 }
 
 static void
@@ -1105,11 +1087,11 @@ sparse_numbytes_decoder (struct tar_stat_info *st, char const *arg)
   uintmax_t u;
   if (decode_num (&u, arg, SIZE_MAX, "GNU.sparse.numbytes"))
     {
-      if (st->sparse_map_avail == st->sparse_map_size)
-       st->sparse_map = x2nrealloc (st->sparse_map,
-                                    &st->sparse_map_size,
-                                    sizeof st->sparse_map[0]);
-      st->sparse_map[st->sparse_map_avail++].numbytes = u;
+      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));
     }
 }
 
This page took 0.029304 seconds and 4 git commands to generate.