Files
tar/src/warning.c
T
Paul Eggert 238250f19e Prefer streq/memeq when they will do
Gnulib’s new streq and memeq functions make code a bit more
readable and, we hope, a bit more reliable and easy to maintain.
* gnulib.modules: Add stringeq.
* lib/wordsplit.c (wordsplit_find_env):
* src/buffer.c (check_compressed_archive, check_tty)
(_open_archive, new_volume, try_new_volume)
(drop_volume_label_suffix):
* src/checkpoint.c (checkpoint_compile_action):
* src/compare.c (process_rawdata, diff_symlink):
* src/create.c (cachedir_file_p):
* src/delete.c (delete_archive_members):
* src/exclist.c (hg_addfn, get_vcs_ignore_file):
* src/extract.c (ds_compare, remove_delayed_set_stat)
(fixup_delayed_set_stat, apply_nonancestor_delayed_set_stat)
(extract_link):
* src/incremen.c (nfs_file_stat, compare_directory_canonical_names)
(procdir):
* src/list.c (read_header, decode_header):
* src/misc.c (replace_prefix):
* src/names.c (uname_to_uid, gname_to_gid, read_next_name)
(name_compare):
* src/sparse.c (check_data_region):
* src/suffix.c (find_compression_suffix):
* src/system.c (sys_detect_dev_null_output)
(sys_child_open_for_compress, sys_child_open_for_uncompress):
* src/tar.c (set_archive_format, tar_set_quoting_style)
(optloc_eq, set_use_compress_program_option, decode_signal)
(report_textual_dates, decode_options):
* src/update.c (update_archive):
* src/warning.c (set_warning_option):
* src/xattrs.c (xattrs_xattrs_set):
* src/xheader.c (xheader_keyword_override_p)
(xheader_set_keyword_equal, locate_handler)
(xheader_protected_keyword_p):
Prefer memeq/streq to memcmp/strcmp when either will do.
2025-11-15 15:10:48 -08:00

130 lines
2.7 KiB
C

/* Warnings for GNU tar.
Copyright 2009-2025 Free Software Foundation, Inc.
This file is part of GNU tar.
GNU tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
GNU tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <system.h>
#include <argmatch.h>
#include "common.h"
static char const *const warning_args[] = {
"all",
"alone-zero-block",
"bad-dumpdir",
"cachedir",
"contiguous-cast",
"file-changed",
"file-ignored",
"file-removed",
"file-shrank",
"file-unchanged",
"filename-with-nuls",
"ignore-archive",
"ignore-newer",
"new-directory",
"rename-directory",
"symlink-cast",
"timestamp",
"unknown-cast",
"unknown-keyword",
"xdev",
"decompress-program",
"existing-file",
"xattr-write",
"record-size",
"failed-read",
"missing-zero-blocks",
"verbose",
"empty-transform",
NULL
};
static int warning_types[] = {
WARN_ALL,
WARN_ALONE_ZERO_BLOCK,
WARN_BAD_DUMPDIR,
WARN_CACHEDIR,
WARN_CONTIGUOUS_CAST,
WARN_FILE_CHANGED,
WARN_FILE_IGNORED,
WARN_FILE_REMOVED,
WARN_FILE_SHRANK,
WARN_FILE_UNCHANGED,
WARN_FILENAME_WITH_NULS,
WARN_IGNORE_ARCHIVE,
WARN_IGNORE_NEWER,
WARN_NEW_DIRECTORY,
WARN_RENAME_DIRECTORY,
WARN_SYMLINK_CAST,
WARN_TIMESTAMP,
WARN_UNKNOWN_CAST,
WARN_UNKNOWN_KEYWORD,
WARN_XDEV,
WARN_DECOMPRESS_PROGRAM,
WARN_EXISTING_FILE,
WARN_XATTR_WRITE,
WARN_RECORD_SIZE,
WARN_FAILED_READ,
WARN_MISSING_ZERO_BLOCKS,
WARN_VERBOSE_WARNINGS,
WARN_EMPTY_TRANSFORM
};
ARGMATCH_VERIFY (warning_args, warning_types);
int warning_option = WARN_ALL & ~(WARN_VERBOSE_WARNINGS|WARN_MISSING_ZERO_BLOCKS);
void
set_warning_option (const char *arg)
{
bool negate = false;
int option;
if (streq (arg, "none"))
{
warning_option = 0;
return;
}
if (strncmp (arg, "no-", 3) == 0)
{
negate = true;
arg += 3;
}
option = XARGMATCH ("--warning", arg,
warning_args, warning_types);
if (negate)
warning_option &= ~option;
else
warning_option |= option;
}
void
warnopt (int opt, int errnum, char const *format, ...)
{
if (warning_enabled (opt))
{
if (error_hook)
error_hook ();
va_list ap;
va_start (ap, format);
verror (0, errnum, format, ap);
va_end (ap);
}
}