Most of these can be caught by configuring with --enable-gcc-warnings.
Problem reported by Pavel Raiskup in:
http://lists.gnu.org/archive/html/bug-tar/2015-09/msg00001.html
* src/buffer.c (format_total_stats):
Prefer pointer to const when it’s OK to use const.
(default_total_format): Now const.
* src/buffer.c (default_total_format):
* src/exclist.c (excfile_head, excfile_tail, vcs_ignore_files):
* src/misc.c (namebuf_add_dir, namebuf_finish):
* src/tar.c (verbatim_files_from_option, option_set_in_cl)
(optloc_eq, set_old_files_option):
Now static.
* src/common.h: Adjust to match the other changes described here.
* src/exclist.c (info_cleanup_exclist):
* src/tar.c (argp_program_version, argp_program_bug_address):
Remove; unused.
(parse_default_options): Define via prototype instead of old style.
(parse_default_options, decode_options):
Fill out incomplete initializers.
char abbr[LONGEST_HUMAN_READABLE + 1];
char rate[LONGEST_HUMAN_READABLE + 1];
int n = 0;
-
+
int human_opts = human_autoscale | human_base_1024 | human_SI | human_B;
if (text && text[0])
before each data item (bytes read, written, deleted, in that order).
EOR is a delimiter to output after each item (used only if deleting
from the archive), EOL is a delimiter to add at the end of the output
- line. */
+ line. */
int
-format_total_stats (FILE *fp, const char **formats, int eor, int eol)
+format_total_stats (FILE *fp, char const *const *formats, int eor, int eol)
{
int n;
-
+
switch (subcommand_option)
{
case CREATE_SUBCOMMAND:
fputc (eor, fp);
n++;
-
+
n += print_stats (fp, formats[TF_WRITE],
prev_written + bytes_written);
return n;
}
-const char *default_total_format[] = {
+static char const *const default_total_format[] = {
N_("Total bytes read"),
/* Amanda 2.4.1p1 looks for "Total bytes written: [0-9][0-9]*". */
N_("Total bytes written"),
/* Unquote filenames */
GLOBAL bool unquote_option;
-/* Treat file names read from -T input verbatim */
-GLOBAL bool verbatim_files_from_option;
-
GLOBAL int savedir_sort_order;
/* Show file or archive names after transformation.
#define TF_READ 0
#define TF_WRITE 1
#define TF_DELETED 2
-int format_total_stats (FILE *fp, const char **formats, int eor, int eol);
+int format_total_stats (FILE *fp, char const *const *formats, int eor, int eol);
void print_total_stats (void);
void mv_begin_write (const char *file_name, off_t totsize, off_t sizeleft);
namebuf_t namebuf_create (const char *dir);
void namebuf_free (namebuf_t buf);
char *namebuf_name (namebuf_t buf, const char *name);
-void namebuf_add_dir (namebuf_t buf, const char *name);
-char *namebuf_finish (namebuf_t buf);
const char *tar_dirname (void);
void excfile_add (const char *name, int flags);
void info_attach_exclist (struct tar_stat_info *dir);
-void info_cleanup_exclist (struct tar_stat_info *dir);
void info_free_exclist (struct tar_stat_info *dir);
bool excluded_name (char const *name, struct tar_stat_info *st);
void exclude_vcs_ignores (void);
char name[1];
};
-struct excfile *excfile_head, *excfile_tail;
+static struct excfile *excfile_head, *excfile_tail;
void
excfile_add (const char *name, int flags)
struct excfile *file;
struct exclist *head = NULL, *tail = NULL, *ent;
struct vcs_ignore_file *vcsfile;
-
+
if (dir->exclude_list)
return;
for (file = excfile_head; file; file = file->next)
if (vcsfile->initfn)
vcsfile->data = vcsfile->initfn (vcsfile->data);
-
+
if (add_exclude_fp (vcsfile->addfn, ex, fp,
EXCLUDE_WILDCARDS|EXCLUDE_ANCHORED, '\n',
vcsfile->data))
FATAL_ERROR ((0, e, "%s", quotearg_colon (file->name)));
}
fclose (fp);
-
+
ent = xmalloc (sizeof (*ent));
ent->excluded = ex;
ent->flags = file->flags == EXCL_DEFAULT
dir->exclude_list = head;
}
-void
-info_cleanup_exclist (struct tar_stat_info *dir)
-{
- struct exclist *ep = dir->exclude_list;
-
- while (ep)
- {
- struct exclist *next = ep->next;
-
- if (ep->flags & EXCL_NON_RECURSIVE)
- {
-
- /* Remove the entry */
- if (ep->prev)
- ep->prev->next = ep->next;
- else
- dir->exclude_list = ep->next;
-
- if (ep->next)
- ep->next->prev = ep->prev;
-
- free_exclude (ep->excluded);
- free (ep);
- }
- ep = next;
- }
-}
-
void
info_free_exclist (struct tar_stat_info *dir)
{
dir->exclude_list = NULL;
}
-
+
/* Return nonzero if file NAME is excluded. */
bool
char *bname = NULL;
bool result;
int nr = 0;
-
+
name += FILE_SYSTEM_PREFIX_LEN (name);
/* Try global exclusion list first */
if (!st)
return false;
-
+
for (result = false; st && !result; st = st->parent, nr = EXCL_NON_RECURSIVE)
{
for (ep = st->exclude_list; ep; ep = ep->next)
continue;
if ((result = excluded_file_name (ep->excluded, name)))
break;
-
+
if (!rname)
{
rname = name;
{
struct wordsplit ws;
size_t i;
-
- if (wordsplit (pattern, &ws,
+
+ if (wordsplit (pattern, &ws,
WRDSF_NOVAR | WRDSF_NOCMD | WRDSF_SQUEEZE_DELIMS))
return;
for (i = 0; i < ws.ws_wordc; i++)
{
int *hgopt;
static int hg_options;
-
+
if (!data)
hgopt = &hg_options;
*hgopt = EXCLUDE_REGEX;
return hgopt;
}
-
+
static void
hg_addfn (struct exclude *ex, char const *pattern, int options, void *data)
{
int *hgopt = data;
size_t len;
-
+
while (isspace (*pattern))
++pattern;
if (*pattern == 0 || *pattern == '#')
--len;
p = xmalloc (len+1);
- memcpy (p, pattern, len);
+ memcpy (p, pattern, len);
p[len] = 0;
pattern = p;
exclude_add_pattern_buffer (ex, p);
options |= FNM_LEADING_DIR|EXCLUDE_ALLOC;
}
-
+
add_exclude (ex, pattern,
((*hgopt == EXCLUDE_REGEX)
? (options & ~EXCLUDE_WILDCARDS)
: (options & ~EXCLUDE_REGEX)) | *hgopt);
}
\f
-struct vcs_ignore_file vcs_ignore_files[] = {
+static struct vcs_ignore_file vcs_ignore_files[] = {
{ ".cvsignore", EXCL_NON_RECURSIVE, cvs_addfn, NULL, NULL },
{ ".gitignore", 0, git_addfn, NULL, NULL },
{ ".bzrignore", 0, bzr_addfn, NULL, NULL },
{ ".hgignore", 0, hg_addfn, hg_initfn , NULL },
{ NULL, 0, git_addfn, NULL, NULL }
};
-
+
static struct vcs_ignore_file *
get_vcs_ignore_file (const char *name)
{
# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
#endif
+static void namebuf_add_dir (namebuf_t, char const *);
+static char *namebuf_finish (namebuf_t);
static const char *tar_getcdpath (int);
\f
return buf->buffer;
}
-void
+static void
namebuf_add_dir (namebuf_t buf, const char *name)
{
static char dirsep[] = { DIRECTORY_SEPARATOR, 0 };
buf->dir_length += strlen (name);
}
-char *
+static char *
namebuf_finish (namebuf_t buf)
{
char *res = buf->buffer;
/* Number of allocated tape drive names. */
static size_t allocated_archive_names;
+/* Treat file names read from -T input verbatim */
+static bool verbatim_files_from_option;
+
\f
/* Miscellaneous. */
XATTR_INCLUDE
};
-const char *argp_program_version = "tar (" PACKAGE_NAME ") " VERSION;
-const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
static char const doc[] = N_("\
GNU 'tar' saves many files together into a single tape or disk archive, \
and can restore individual files from the archive.\n\
" for FILE itself"), GRID+1 },
{"exclude-ignore", EXCLUDE_IGNORE_OPTION, N_("FILE"), 0,
N_("read exclude patterns for each directory from FILE, if it exists"),
- GRID+1 },
+ GRID+1 },
{"exclude-ignore-recursive", EXCLUDE_IGNORE_RECURSIVE_OPTION, N_("FILE"), 0,
N_("read exclude patterns for each directory and its subdirectories "
"from FILE, if it exists"), GRID+1 },
OC_COMPRESS, /* Compress options: -JjZz, -I, etc. */
OC_OCCURRENCE, /* --occurrence */
OC_LISTED_INCREMENTAL, /* --listed-incremental */
- OC_NEWER, /* --newer, --newer-mtime, --after-date */
- OC_VERIFY, /* --verify */
+ OC_NEWER, /* --newer, --newer-mtime, --after-date */
+ OC_VERIFY, /* --verify */
OC_STARTING_FILE, /* --starting-file */
OC_SAME_ORDER, /* --same-order */
OC_ONE_TOP_LEVEL, /* --one-top-level */
}
/* Return true if the latest occurrence of option ID was in the command line */
-int
+static int
option_set_in_cl (int id)
{
struct option_locus *loc = optloc_lookup (id);
}
/* Compare two option locations */
-int
+static int
optloc_eq (struct option_locus *a, struct option_locus *b)
{
if (a->source != b->source)
case LZOP_OPTION:
s = xasprintf (_("filter the archive through %s"), LZOP_PROGRAM);
-
+
case 'J':
s = xasprintf (_("filter the archive through %s"), XZ_PROGRAM);
break;
ARGMATCH_VERIFY (sort_mode_arg, sort_mode_flag);
\f
-void
+static void
set_old_files_option (int code, struct option_locus *loc)
{
struct option_locus *prev;
- static char *code_to_opt[] = {
+ static char const *const code_to_opt[] = {
"--overwrite-dir",
"--no-overwrite-dir",
"--overwrite",
prev = optloc_save (OC_OLD_FILES, loc);
if (prev && optloc_eq (loc, prev) && code != old_files_option)
option_conflict_error (code_to_opt[code], code_to_opt[old_files_option]);
-
+
old_files_option = code;
}
\f
parse_opt (int key, char *arg, struct argp_state *state)
{
struct tar_args *args = state->input;
-
+
switch (key)
{
case ARGP_KEY_ARG:
case EXCLUDE_IGNORE_RECURSIVE_OPTION:
excfile_add (arg, EXCL_RECURSIVE);
break;
-
+
case EXCLUDE_TAG_OPTION:
add_exclusion_tag (arg, exclusion_tag_contents, NULL);
break;
case EXCLUDE_VCS_IGNORES_OPTION:
exclude_vcs_ignores ();
break;
-
+
case FORCE_LOCAL_OPTION:
force_local_option = true;
break;
case NO_VERBATIM_FILES_FROM_OPTION:
verbatim_files_from_option = false;
break;
-
+
case WARNING_OPTION:
set_warning_option (arg);
break;
else if (args->loc->source == OPTS_ENVIRON)
error (0, 0, _("error parsing %s"), args->loc->name);
exit (EX_USAGE);
-
+
default:
return ARGP_ERR_UNKNOWN;
}
if (argp_parse (&argp, argc, argv, ARGP_IN_ORDER|ARGP_NO_EXIT, &idx, &args))
abort (); /* shouldn't happen */
if (loc->source == OPTS_ENVIRON && args.input_files)
- USAGE_ERROR ((0, 0, _("non-option arguments in %s"), loc->name));
+ USAGE_ERROR ((0, 0, _("non-option arguments in %s"), loc->name));
}
-void
-parse_default_options ()
+static void
+parse_default_options (void)
{
char *opts = getenv ("TAR_OPTIONS");
struct wordsplit ws;
- struct option_locus loc = { OPTS_ENVIRON, "TAR_OPTIONS", 0 };
-
+ struct option_locus loc = { OPTS_ENVIRON, "TAR_OPTIONS", 0, 0 };
+
if (!opts)
return;
ws.ws_wordv[0] = program_invocation_short_name;
more_options (ws.ws_offs + ws.ws_wordc, ws.ws_wordv, &loc);
}
-
+
wordsplit_free (&ws);
}
decode_options (int argc, char **argv)
{
int idx;
- struct option_locus loc = { OPTS_COMMAND_LINE };
-
+ struct option_locus loc = { OPTS_COMMAND_LINE, 0, 0, 0 };
+
argp_version_setup ("tar", tar_authors);
/* Set some default option values. */
blocking_factor = DEFAULT_BLOCKING;
record_size = DEFAULT_BLOCKING * BLOCKSIZE;
excluded = new_exclude ();
-
+
newer_mtime_option.tv_sec = TYPE_MINIMUM (time_t);
newer_mtime_option.tv_nsec = -1;
recursion_option = FNM_LEADING_DIR;
tar_sparse_minor = 0;
savedir_sort_order = SAVEDIR_SORT_NONE;
-
+
owner_option = -1; owner_name_option = NULL;
group_option = -1; group_name_option = NULL;
occurrence_option = 0;
}
}
-
+
if (archive_names == 0)
{
/* If no archive file name given, try TAPE from the environment, or
else
memset (&newer_mtime_option, 0, sizeof (newer_mtime_option));
}
-
+
if (incremental_level != -1 && !listed_incremental_option)
WARN ((0, 0,
_("--level is meaningless without --listed-incremental")));
if (one_top_level_option)
{
char *base;
-
+
if (absolute_names_option)
{
struct option_locus *one_top_level_loc =
else
one_top_level_option = false;
}
-
+
if (one_top_level_option && !one_top_level_dir)
{
/* If the user wants to guarantee that everything is under one
exit_failure = TAREXIT_FAILURE;
exit_status = TAREXIT_SUCCESS;
error_hook = checkpoint_flush_actions;
-
+
filename_terminator = '\n';
set_quoting_style (0, DEFAULT_QUOTING_STYLE);
}
checkpoint_finish ();
-
+
if (totals_option)
print_total_stats ();