]> Dogcows Code - chaz/tar/blobdiff - src/xheader.c
(atime_decoder,gid_decoder,ctime_decoder)
[chaz/tar] / src / xheader.c
index aa94c4bf2dfb1575d71565bcb7a9121a01c76500..d5a75b3e32d8678348fca82b7dcdbe37db3751bc 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <hash.h>
 #include <quotearg.h>
+#include <xstrtol.h>
 
 #include "common.h"
 
@@ -36,10 +37,13 @@ struct xhdr_tab
   void (*decoder) (struct tar_stat_info *, char const *);
 };
 
-/* This declaration must specify the number of elements in xhdr_tab,
-   because ISO C99 section 6.9.2 prohibits a tentative definition that
-   has both internal linkage and incomplete type.  */
-static struct xhdr_tab const xhdr_tab[13];
+/* This declaration must be extern, because ISO C99 section 6.9.2
+   prohibits a tentative definition that has both internal linkage and
+   incomplete type.  If we made it static, we'd have to declare its
+   size which would be a maintenance pain; if we put its initializer
+   here, we'd need a boatload of forward declarations, which would be
+   even more of a pain.  */
+extern struct xhdr_tab const xhdr_tab[];
 
 static struct xhdr_tab const *
 locate_handler (char const *keyword)
@@ -287,7 +291,9 @@ atime_coder (struct tar_stat_info const *st, char const *keyword,
 static void
 atime_decoder (struct tar_stat_info *st, char const *arg)
 {
-  st->stat.st_atime = strtoul (arg, NULL, 0);
+  uintmax_t u;
+  if (xstrtoumax (arg, 0, 10, &u, "") == LONGINT_OK)
+    st->stat.st_atime = u;
 }
 
 static void
@@ -300,7 +306,9 @@ gid_coder (struct tar_stat_info const *st, char const *keyword,
 static void
 gid_decoder (struct tar_stat_info *st, char const *arg)
 {
-  st->stat.st_gid = strtoul (arg, NULL, 0);
+  uintmax_t u;
+  if (xstrtoumax (arg, 0, 10, &u, "") == LONGINT_OK)
+    st->stat.st_gid = u;
 }
 
 static void
@@ -339,7 +347,9 @@ ctime_coder (struct tar_stat_info const *st, char const *keyword,
 static void
 ctime_decoder (struct tar_stat_info *st, char const *arg)
 {
-  st->stat.st_ctime = strtoul (arg, NULL, 0);
+  uintmax_t u;
+  if (xstrtoumax (arg, 0, 10, &u, "") == LONGINT_OK)
+    st->stat.st_ctime = u;
 }
 
 static void
@@ -352,7 +362,9 @@ mtime_coder (struct tar_stat_info const *st, char const *keyword,
 static void
 mtime_decoder (struct tar_stat_info *st, char const *arg)
 {
-  st->stat.st_mtime = strtoul (arg, NULL, 0);
+  uintmax_t u;
+  if (xstrtoumax (arg, 0, 10, &u, "") == LONGINT_OK)
+    st->stat.st_mtime = u;
 }
 
 static void
@@ -380,7 +392,9 @@ size_coder (struct tar_stat_info const *st, char const *keyword,
 static void
 size_decoder (struct tar_stat_info *st, char const *arg)
 {
-  st->stat.st_size = strtoul (arg, NULL, 0);
+  uintmax_t u;
+  if (xstrtoumax (arg, 0, 10, &u, "") == LONGINT_OK)
+    st->stat.st_size = u;
 }
 
 static void
@@ -393,7 +407,9 @@ uid_coder (struct tar_stat_info const *st, char const *keyword,
 static void
 uid_decoder (struct tar_stat_info *st, char const *arg)
 {
-  st->stat.st_uid = strtoul (arg, NULL, 0);
+  uintmax_t u;
+  if (xstrtoumax (arg, 0, 10, &u, "") == LONGINT_OK)
+    st->stat.st_uid = u;
 }
 
 static void
@@ -409,7 +425,7 @@ uname_decoder (struct tar_stat_info *st, char const *arg)
   assign_string (&st->uname, arg);
 }
 
-static struct xhdr_tab const xhdr_tab[] = {
+struct xhdr_tab const xhdr_tab[] = {
   { "atime",   atime_coder,    atime_decoder   },
   { "comment", dummy_coder,    dummy_decoder   },
   { "charset", dummy_coder,    dummy_decoder   },
This page took 0.027809 seconds and 4 git commands to generate.