bool absolute_names_option;
bool utc_option;
bool full_time_option;
-int after_date_option;
+bool after_date_option;
enum atime_preserve atime_preserve_option;
bool backup_option;
enum backup_type backup_type;
int same_permissions_option;
int selinux_context_option;
int acls_option;
-int xattrs_option;
+bool xattrs_option;
idx_t strip_name_components;
bool show_omitted_dirs_option;
bool sparse_option;
#endif
/* Print a message if not all links are dumped */
-static int check_links_option;
+static bool check_links_option;
/* Number of allocated tape drive names. */
static idx_t allocated_archive_names;
}
/* Returns true if and only if the user typed an affirmative response. */
-int
+bool
confirm (const char *message_action, const char *message_name)
{
static FILE *confirm_file;
- static int confirm_file_EOF;
+ static bool confirm_file_EOF;
bool status = false;
if (!confirm_file)
char *response = NULL;
size_t response_size = 0;
if (getline (&response, &response_size, confirm_file) < 0)
- confirm_file_EOF = 1;
+ confirm_file_EOF = true;
else
status = rpmatch (response) > 0;
free (response);
}
static void
-set_xattr_option (int value)
+set_xattr_option (bool value)
{
- if (value == 1)
+ if (value)
set_archive_format ("posix");
xattrs_option = value;
}
static void
tar_list_quoting_styles (struct obstack *stk, char const *prefix)
{
- int i;
idx_t prefixlen = strlen (prefix);
- for (i = 0; quoting_style_args[i]; i++)
+ for (idx_t i = 0; quoting_style_args[i]; i++)
{
obstack_grow (stk, prefix, prefixlen);
obstack_grow (stk, quoting_style_args[i],
static void
tar_set_quoting_style (char *arg)
{
- int i;
-
- for (i = 0; quoting_style_args[i]; i++)
+ for (idx_t i = 0; quoting_style_args[i]; i++)
if (strcmp (arg, quoting_style_args[i]) == 0)
{
set_quoting_style (NULL, i);
/* Return location of a recent option of class ID */
static struct option_locus *
-optloc_lookup (int id)
+optloc_lookup (enum option_class id)
{
return option_class[id];
}
/* Return true if the latest occurrence of option ID was in the command line */
-static int
-option_set_in_cl (int id)
+static bool
+option_set_in_cl (enum option_class id)
{
struct option_locus *loc = optloc_lookup (id);
- if (!loc)
- return 0;
- return loc->source == OPTS_COMMAND_LINE;
+ return loc && loc->source == OPTS_COMMAND_LINE;
}
/* Compare two option locations */
-static int
+static bool
optloc_eq (struct option_locus *a, struct option_locus *b)
{
assume (a); /* Pacify GCC bug 106436. */
if (a->source != b->source)
- return 0;
+ return false;
if (a->source == OPTS_COMMAND_LINE)
- return 1;
+ return true;
assume (a->name);
return strcmp (a->name, b->name) == 0;
}
{
static struct sigtab
{
- char const *name;
+ char name[sizeof "USR1"];
int signo;
} const sigtab[] = {
{ "USR1", SIGUSR1 },
{ "INT", SIGINT },
{ "QUIT", SIGQUIT }
};
- struct sigtab const *p;
+ enum { nsigtab = sizeof sigtab / sizeof *sigtab };
char const *s = name;
if (strncmp (s, "SIG", 3) == 0)
s += 3;
- for (p = sigtab; p < sigtab + sizeof (sigtab) / sizeof (sigtab[0]); p++)
+ for (struct sigtab const *p = sigtab; p < sigtab + nsigtab; p++)
if (strcmp (p->name, s) == 0)
return p->signo;
paxfatal (0, _("Unknown signal name: %s"), name);
char *date;
};
-static int
+static bool
get_date_or_file (struct tar_args *args, const char *option,
const char *str, struct timespec *ts)
{
paxwarn (0, _("Substituting %s for unknown date format %s"),
tartime (*ts, false), quote (str));
ts->tv_nsec = 0;
- return 1;
+ return false;
}
else
{
args->textual_date = p;
}
}
- return 0;
+ return true;
}
static void
char *tmp = xmalloc (len);
memcpy (tmp, p + 1, len-2);
tmp[len-2] = 0;
- if (get_date_or_file (targs, "--pax-option", tmp, &ts) == 0)
+ if (get_date_or_file (targs, "--pax-option", tmp, &ts))
{
char buf[TIMESPEC_STRSIZE_BOUND];
char const *s = code_timespec (ts, buf);
NULL
};
-static int sort_mode_flag[] = {
+static enum savedir_option const sort_mode_flag[] = {
SAVEDIR_SORT_NONE,
SAVEDIR_SORT_NAME,
#if D_INO_IN_DIRENT
"raw", "seek", NULL
};
-static int const hole_detection_types[] =
+static enum hole_detection_method const hole_detection_types[] =
{
HOLE_DETECTION_RAW, HOLE_DETECTION_SEEK
};
\f
static void
-set_old_files_option (int code, struct option_locus *loc)
+set_old_files_option (enum old_files code, struct option_locus *loc)
{
struct option_locus *prev;
/* Option compatibility map. 0 means two options are incompatible. */
{
case ARGP_KEY_INIT:
if (state->root_argp->children)
- {
- int i;
-
- for (i = 0; state->root_argp->children[i].argp; i++)
- state->child_inputs[i] = state->input;
- }
+ for (idx_t i = 0; state->root_argp->children[i].argp; i++)
+ state->child_inputs[i] = state->input;
break;
case ARGP_KEY_ARG:
#ifdef DEVICE_PREFIX
{
int device = key - '0';
- int density;
- static char buf[sizeof DEVICE_PREFIX + 10];
- char *cursor;
+ static char buf[sizeof DEVICE_PREFIX + INT_STRLEN_BOUND (int)]
+ = DEVICE_PREFIX;
if (arg[1])
argp_error (state, _("Malformed density argument: %s"), quote (arg));
- strcpy (buf, DEVICE_PREFIX);
- cursor = buf + strlen (buf);
+ char *cursor = buf + sizeof DEVICE_PREFIX - 1;
#ifdef DENSITY_LETTER
break;
case 'l':
- check_links_option = 1;
+ check_links_option = true;
break;
case 'L':
break;
case XATTR_OPTION:
- set_xattr_option (1);
+ set_xattr_option (true);
break;
case NO_XATTR_OPTION:
- set_xattr_option (-1);
+ set_xattr_option (false);
break;
case XATTR_INCLUDE:
case XATTR_EXCLUDE:
- set_xattr_option (1);
+ set_xattr_option (true);
xattrs_mask_add (arg, (key == XATTR_INCLUDE));
break;
/* Parse the options for tar. */
static struct argp_option const *
-find_argp_option_key (struct argp_option const *o, int key)
+find_argp_option_key (struct argp_option const *o, char key)
{
for (;
!(o->name == NULL
}
static struct argp_option const *
-find_argp_option (struct argp *ap, int key)
+find_argp_option (struct argp *ap, char key)
{
struct argp_option const *p = NULL;
struct argp_child const *child;
};
\f
/* Subcommand classes */
-enum
+enum subcommand_class
{
SUBCL_READ = 1 << 0, /* Reads from the archive. */
SUBCL_WRITE = 1 << 1, /* Writes to the archive. */
SUBCL_OCCUR = 1 << 4, /* Allows the use of the occurrence option. */
};
-static int const subcommand_class[] = {
+static char const subcommand_class[] = {
[UNKNOWN_SUBCOMMAND ] = 0,
[APPEND_SUBCOMMAND ] = SUBCL_WRITE | SUBCL_UPDATE,
[CAT_SUBCOMMAND ] = SUBCL_WRITE,
/* Is subcommand_option in class(es) f? */
static bool
-is_subcommand_class (int f)
+is_subcommand_class (enum subcommand_class f)
{
return subcommand_class[subcommand_option] & f;
}
char **new_argv; /* argv value for rearranged arguments */
char *const *in; /* cursor into original argv */
char **out; /* cursor into rearranged argv */
- const char *letter; /* cursor into old option letters */
char buffer[3]; /* constructed option buffer */
/* Initialize a constructed option. */
/* Allocate a new argument array, and copy program name in it. */
- new_argc = argc - 1 + strlen (argv[1]);
- new_argv = xmalloc ((new_argc + 1) * sizeof (char *));
+ idx_t new_arg_slots;
+ if (ckd_add (&new_arg_slots, argc, strlen (argv[1]))
+ || ckd_sub (&new_argc, new_arg_slots, 1))
+ xalloc_die ();
+ new_argv = xinmalloc (new_arg_slots, sizeof *new_argv);
in = argv;
out = new_argv;
*out++ = *in++;
/* Copy each old letter option as a separate option, and have the
corresponding argument moved next to it. */
- for (letter = *in++; *letter; letter++)
+ for (char const *letter = *in++; *letter; letter++)
{
struct argp_option const *opt;
&& !is_subcommand_class (SUBCL_READ))
paxusage (_("--selinux can be used only on POSIX archives"));
- if ((xattrs_option > 0)
+ if (xattrs_option
&& archive_format != POSIX_FORMAT
&& !is_subcommand_class (SUBCL_READ))
paxusage (_("--xattrs can be used only on POSIX archives"));