#include <hash.h>
#include <quotearg.h>
+#include <xstrtol.h>
#include "common.h"
void (*decoder) (struct tar_stat_info *, char const *);
};
-static struct xhdr_tab const xhdr_tab[];
+/* 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)
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
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
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
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
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
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
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 },
{ "uid", uid_coder, uid_decoder },
{ "uname", uname_coder, uname_decoder },
+ /* The number of entries in xhdr_tab must agree with the array
+ bounds in xhdr_tab's forward declaration. */
+
#if 0 /* GNU private keywords (not yet implemented) */
/* Sparse file handling */
{ "GNU.sparse.offset", sparse_offset_coder, sparse_offset_decoder },