>From 280062a812db38f5011e9fe6b9ff55232f40a9db Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Sun, 12 Nov 2017 18:45:53 +0100 Subject: [PATCH] all: use die() rather than error(EXIT_FAILURE) die() has the advantage of being apparent to the compiler that it doesn't return, which will avoid warnings in some cases, and possibly generate better code. While at it, wrap some of the overly long error messages into a new line. * cfg.mk (sc_die_EXIT_FAILURE): A new syntax check rule to catch any new uses of error (CONSTANT, ...); * find/exec.c: Include "die.h" and use die rather than exit (EXIT_FAILURE). * find/fstype.c: Likewise. * find/ftsfind.c: Likewise. * find/oldfind.c: Likewise. * find/parser.c: Likewise. * find/pred.c: Likewise. * find/print.c: Likewise. * find/tree.c: Likewise. * find/util.c: Likewise. * lib/buildcmd.c: Likewise. * lib/listfile.c: Likewise. * lib/regextype.c: Likewise. * lib/safe-atoi.c: Likewise. * locate/frcode.c: Likewise. * locate/locate.c: Likewise. * locate/word_io.c: Likewise. * xargs/xargs.c: Likewise. --- cfg.mk | 10 +++ find/exec.c | 9 ++- find/fstype.c | 4 +- find/ftsfind.c | 7 +- find/oldfind.c | 39 +++++----- find/parser.c | 232 +++++++++++++++++++++++++++---------------------------- find/pred.c | 3 +- find/print.c | 13 ++-- find/tree.c | 78 ++++++++++--------- find/util.c | 43 ++++++----- lib/buildcmd.c | 22 +++--- lib/listfile.c | 3 +- lib/regextype.c | 12 +-- lib/safe-atoi.c | 18 ++--- locate/frcode.c | 29 +++---- locate/locate.c | 49 ++++++------ locate/word_io.c | 7 +- xargs/xargs.c | 111 +++++++++++++++----------- 18 files changed, 366 insertions(+), 323 deletions(-) diff --git a/cfg.mk b/cfg.mk index aa476188..1bc40d2f 100644 --- a/cfg.mk +++ b/cfg.mk @@ -88,6 +88,16 @@ exclude_file_name_regexp--sc_texinfo_acronym = doc/perm\.texi # cases where neither argument is a string literal. local-checks-to-skip += sc_prohibit_strcmp +# Usage of error() with an exit constant, should instead use die(), +# as that avoids warnings and may generate better code, due to being apparent +# to the compiler that it doesn't return. +sc_die_EXIT_FAILURE: + @GIT_PAGER= git grep -E 'error \(.*_(FAILURE|INVALID)' \ + -- find lib locate xargs \ + && { echo '$(ME): '"Use die() instead of error" 1>&2; \ + exit 1; } \ + || : + # During 'make update-copyright', convert a sequence with gaps to the minimal # containing range. update-copyright-env = \ diff --git a/find/exec.c b/find/exec.c index 91ca0988..7e738bac 100644 --- a/find/exec.c +++ b/find/exec.c @@ -37,6 +37,7 @@ /* findutils headers */ #include "buildcmd.h" #include "defs.h" +#include "die.h" #include "fdleak.h" #if ENABLE_NLS @@ -124,9 +125,9 @@ impl_pred_exec (const char *pathname, */ if (!record_exec_dir (execp)) { - error (EXIT_FAILURE, errno, - _("Failed to save working directory in order to " - "run a command on %s"), + die (EXIT_FAILURE, errno, + _("Failed to save working directory in order to " + "run a command on %s"), safely_quote_err_filename (0, pathname)); /*NOTREACHED*/ } @@ -306,7 +307,7 @@ launch (struct buildcmd_control *ctl, void *usercontext, int argc, char **argv) child_pid = fork (); if (child_pid == -1) - error (EXIT_FAILURE, errno, _("cannot fork")); + die (EXIT_FAILURE, errno, _("cannot fork")); if (child_pid == 0) { /* We are the child. */ diff --git a/find/fstype.c b/find/fstype.c index 13c94de1..f9dc8f13 100644 --- a/find/fstype.c +++ b/find/fstype.c @@ -51,11 +51,11 @@ #include "xalloc.h" #include "xstrtol.h" #include "mountlist.h" -#include "error.h" #include "gettext.h" /* find headers. */ #include "defs.h" +#include "die.h" #include "extendbuf.h" #if ENABLE_NLS @@ -244,7 +244,7 @@ file_system_type_uncached (const struct stat *statp, const char *path, * use because gnulib has abstracted all that stuff away. * Hence we cannot issue a specific error message here. */ - error (EXIT_FAILURE, 0, _("Cannot read mounted file system list")); + die (EXIT_FAILURE, 0, _("Cannot read mounted file system list")); } for (type=NULL, entry=entries; entry; entry=entry->me_next) { diff --git a/find/ftsfind.c b/find/ftsfind.c index c4c849a8..0b448dff 100644 --- a/find/ftsfind.c +++ b/find/ftsfind.c @@ -51,6 +51,7 @@ /* find headers. */ #include "defs.h" +#include "die.h" #include "dircallback.h" #include "fdleak.h" #include "unused-result.h" @@ -666,8 +667,8 @@ main (int argc, char **argv) state.shared_files = sharefile_init ("w"); if (NULL == state.shared_files) { - error (EXIT_FAILURE, errno, - _("Failed to initialize shared-file hash table")); + die (EXIT_FAILURE, errno, + _("Failed to initialize shared-file hash table")); } /* Set the option defaults before we do the locale initialisation as @@ -683,7 +684,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (atexit (close_stdout)) { - error (EXIT_FAILURE, errno, _("The atexit library function failed")); + die (EXIT_FAILURE, errno, _("The atexit library function failed")); } /* Check for -P, -H or -L options. Also -D and -O, which are diff --git a/find/oldfind.c b/find/oldfind.c index 70f3fb25..771d3c96 100644 --- a/find/oldfind.c +++ b/find/oldfind.c @@ -51,6 +51,7 @@ /* find headers. */ #include "buildcmd.h" #include "defs.h" +#include "die.h" #include "fdleak.h" #undef STAT_MOUNTPOINTS @@ -185,8 +186,8 @@ main (int argc, char **argv) state.shared_files = sharefile_init ("w"); if (NULL == state.shared_files) { - error (EXIT_FAILURE, errno, - _("Failed to initialize shared-file hash table")); + die (EXIT_FAILURE, errno, + _("Failed to initialize shared-file hash table")); } /* Set the option defaults before we do the locale @@ -202,7 +203,7 @@ main (int argc, char **argv) textdomain (PACKAGE); if (atexit (close_stdin)) { - error (EXIT_FAILURE, errno, _("The atexit library function failed")); + die (EXIT_FAILURE, errno, _("The atexit library function failed")); } /* Check for -P, -H or -L options. */ @@ -245,7 +246,7 @@ main (int argc, char **argv) set_stat_placeholders (&starting_stat_buf); if ((*options.xstat) (".", &starting_stat_buf) != 0) - error (EXIT_FAILURE, errno, _("cannot stat current directory")); + die (EXIT_FAILURE, errno, _("cannot stat current directory")); /* If no paths are given, default to ".". */ for (i = end_of_leading_options; i < argc && !looks_like_expression (argv[i], true); i++) @@ -336,7 +337,7 @@ init_mounted_dev_list (int mandatory) mounted_devices = get_mounted_devices (&num_mounted_devices); if (mandatory && (NULL == mounted_devices)) { - error (EXIT_FAILURE, 0, _("Cannot read list of mounted devices.")); + die (EXIT_FAILURE, 0, _("Cannot read list of mounted devices.")); } } @@ -531,15 +532,15 @@ wd_sanity_check (const char *thing_to_stat, case FATAL_IF_SANITY_CHECK_FAILS: { fstype = filesystem_type (newinfo, current_dir); - error (EXIT_FAILURE, 0, - _("%s%s changed during execution of %s (old device number %ld, new device number %ld, file system type is %s) [ref %ld]"), - safely_quote_err_filename (0, specific_what), - parent ? "/.." : "", - safely_quote_err_filename (1, progname), - (long) old_dev, - (long) newinfo->st_dev, - fstype, - (long)line_no); + die (EXIT_FAILURE, 0, + _("%s%s changed during execution of %s (old device number %ld, new device number %ld, file system type is %s) [ref %ld]"), + safely_quote_err_filename (0, specific_what), + parent ? "/.." : "", + safely_quote_err_filename (1, progname), + (long) old_dev, + (long) newinfo->st_dev, + fstype, + (long)line_no); /*NOTREACHED*/ return false; } @@ -733,8 +734,8 @@ safely_chdir_lstat (const char *dest, * can't recover from this and so this error * is fatal. */ - error (EXIT_FAILURE, errno, - _("failed to return to parent directory")); + die (EXIT_FAILURE, errno, + _("failed to return to parent directory")); } } else @@ -1535,7 +1536,7 @@ process_dir (const char *pathname, const char *name, int pathlen, const struct s break; case SafeChdirFailWouldBeUnableToReturn: - error (EXIT_FAILURE, errno, "."); + die (EXIT_FAILURE, errno, "."); return; case SafeChdirFailNonexistent: @@ -1544,8 +1545,8 @@ process_dir (const char *pathname, const char *name, int pathlen, const struct s case SafeChdirFailSymlink: case SafeChdirFailNotDir: case SafeChdirFailChdirFailed: - error (EXIT_FAILURE, errno, - "%s", safely_quote_err_filename (0, pathname)); + die (EXIT_FAILURE, errno, + "%s", safely_quote_err_filename (0, pathname)); return; } } diff --git a/find/parser.c b/find/parser.c index f7c4a079..8650da15 100644 --- a/find/parser.c +++ b/find/parser.c @@ -63,6 +63,7 @@ /* find headers. */ #include "buildcmd.h" #include "defs.h" +#include "die.h" #include "fdleak.h" #include "findutils-version.h" @@ -453,11 +454,11 @@ check_option_combinations (const struct predicate *p) if (!options.explicit_depth) { /* This fixes Savannah bug #20865. */ - error (EXIT_FAILURE, 0, - _("The -delete action automatically turns on -depth, " - "but -prune does nothing when -depth is in effect. " - "If you want to carry on anyway, just explicitly use " - "the -depth option.")); + die (EXIT_FAILURE, 0, + _("The -delete action automatically turns on -depth, " + "but -prune does nothing when -depth is in effect. " + "If you want to carry on anyway, just explicitly use " + "the -depth option.")); } } } @@ -1162,12 +1163,12 @@ parse_group (const struct parser_table* entry, char **argv, int *arg_ptr) else { /* XXX: no test in test suite for this */ - error (EXIT_FAILURE, 0, - _("%s is not the name of an existing group and" - " it does not look like a numeric group ID " - "because it has the unexpected suffix %s"), - quotearg_n_style (0, options.err_quoting_style, groupname), - quotearg_n_style (1, options.err_quoting_style, groupname+gid_len)); + die (EXIT_FAILURE, 0, + _("%s is not the name of an existing group and" + " it does not look like a numeric group ID " + "because it has the unexpected suffix %s"), + quotearg_n_style (0, options.err_quoting_style, groupname), + quotearg_n_style (1, options.err_quoting_style, groupname+gid_len)); *arg_ptr = saved_argc; /* don't consume the invalid argument. */ return false; } @@ -1177,14 +1178,14 @@ parse_group (const struct parser_table* entry, char **argv, int *arg_ptr) if (*groupname) { /* XXX: no test in test suite for this */ - error (EXIT_FAILURE, 0, - _("%s is not the name of an existing group"), - quotearg_n_style (0, options.err_quoting_style, groupname)); + die (EXIT_FAILURE, 0, + _("%s is not the name of an existing group"), + quotearg_n_style (0, options.err_quoting_style, groupname)); } else { - error (EXIT_FAILURE, 0, - _("argument to -group is empty, but should be a group name")); + die (EXIT_FAILURE, 0, + _("argument to -group is empty, but should be a group name")); } *arg_ptr = saved_argc; /* don't consume the invalid argument. */ return false; @@ -1256,8 +1257,8 @@ fnmatch_sanitycheck (void) || 0 == fnmatch ("Foo", "foo", 0) || 0 != fnmatch ("Foo", "foo", FNM_CASEFOLD)) { - error (EXIT_FAILURE, 0, - _("sanity check of the fnmatch() library function failed.")); + die (EXIT_FAILURE, 0, + _("sanity check of the fnmatch() library function failed.")); return false; } checked = true; @@ -1396,10 +1397,10 @@ insert_depthspec (const struct parser_table* entry, char **argv, int *arg_ptr, return parse_noop (entry, argv, arg_ptr); } } - error (EXIT_FAILURE, 0, - _("Expected a positive decimal integer argument to %s, but got %s"), - predicate, - quotearg_n_style (0, options.err_quoting_style, depthstr)); + die (EXIT_FAILURE, 0, + _("Expected a positive decimal integer argument to %s, but got %s"), + predicate, + quotearg_n_style (0, options.err_quoting_style, depthstr)); /* NOTREACHED */ return false; } @@ -1583,8 +1584,8 @@ parse_newerXY (const struct parser_table* entry, char **argv, int *arg_ptr) */ if (argv[1+*arg_ptr] == NULL) { - error (EXIT_FAILURE, 0, _("The %s test needs an argument"), - quotearg_n_style (0, options.err_quoting_style, argv[*arg_ptr])); + die (EXIT_FAILURE, 0, _("The %s test needs an argument"), + quotearg_n_style (0, options.err_quoting_style, argv[*arg_ptr])); } else { @@ -1619,9 +1620,9 @@ parse_newerXY (const struct parser_table* entry, char **argv, int *arg_ptr) argv[*arg_ptr], &options.start_time)) { - error (EXIT_FAILURE, 0, - _("I cannot figure out how to interpret %s as a date or time"), - quotearg_n_style (0, options.err_quoting_style, argv[*arg_ptr])); + die (EXIT_FAILURE, 0, + _("I cannot figure out how to interpret %s as a date or time"), + quotearg_n_style (0, options.err_quoting_style, argv[*arg_ptr])); } } else @@ -1636,9 +1637,9 @@ parse_newerXY (const struct parser_table* entry, char **argv, int *arg_ptr) if (!get_stat_Ytime (&stat_newer, y, &our_pred->args.reftime.ts)) { /* We cannot extract a timestamp from the struct stat. */ - error (EXIT_FAILURE, 0, - _("Cannot obtain birth time of file %s"), - safely_quote_err_filename (0, argv[*arg_ptr])); + die (EXIT_FAILURE, 0, + _("Cannot obtain birth time of file %s"), + safely_quote_err_filename (0, argv[*arg_ptr])); } } our_pred->args.reftime.kind = COMP_GT; @@ -1876,8 +1877,8 @@ parse_perm (const struct parser_table* entry, char **argv, int *arg_ptr) and it would be confusing if 'find' continued to support it. */ if (NULL == change || (perm_expr[0] == '+' && '0' <= perm_expr[1] && perm_expr[1] < '8')) - error (EXIT_FAILURE, 0, _("invalid mode %s"), - quotearg_n_style (0, options.err_quoting_style, perm_expr)); + die (EXIT_FAILURE, 0, _("invalid mode %s"), + quotearg_n_style (0, options.err_quoting_style, perm_expr)); perm_val[0] = mode_adjust (0, false, 0, change, NULL); perm_val[1] = mode_adjust (0, true, 0, change, NULL); free (change); @@ -2066,9 +2067,9 @@ insert_regex (char **argv, error_message = re_compile_pattern (rx, strlen (rx), re); if (error_message) - error (EXIT_FAILURE, 0, - _("failed to compile regular expression '%s': %s"), - rx, error_message); + die (EXIT_FAILURE, 0, + _("failed to compile regular expression '%s': %s"), + rx, error_message); our_pred->est_success_rate = estimate_pattern_match_rate (rx, 1); return true; } @@ -2096,7 +2097,7 @@ parse_size (const struct parser_table* entry, char **argv, int *arg_ptr) len = strlen (arg); if (len == 0) - error (EXIT_FAILURE, 0, _("invalid null argument to -size")); + die (EXIT_FAILURE, 0, _("invalid null argument to -size")); suffix = arg[len - 1]; switch (suffix) @@ -2145,8 +2146,8 @@ parse_size (const struct parser_table* entry, char **argv, int *arg_ptr) break; default: - error (EXIT_FAILURE, 0, - _("invalid -size type `%c'"), argv[*arg_ptr][len - 1]); + die (EXIT_FAILURE, 0, + _("invalid -size type `%c'"), argv[*arg_ptr][len - 1]); } /* TODO: accept fractional mebibytes etc. ? */ if (!get_num (arg, &num, &c_type)) @@ -2155,9 +2156,9 @@ parse_size (const struct parser_table* entry, char **argv, int *arg_ptr) tail[0] = suffix; tail[1] = 0; - error (EXIT_FAILURE, 0, - _("Invalid argument `%s%s' to -size"), - arg, tail); + die (EXIT_FAILURE, 0, + _("Invalid argument `%s%s' to -size"), + arg, tail); return false; } our_pred = insert_primary (entry, arg); @@ -2344,7 +2345,7 @@ parse_show_control_chars (const struct parser_table* entry, if ((argv == NULL) || (argv[*arg_ptr] == NULL)) { - error (EXIT_FAILURE, errno, "%s", errmsg); + die (EXIT_FAILURE, errno, "%s", errmsg); return false; } else @@ -2361,7 +2362,7 @@ parse_show_control_chars (const struct parser_table* entry, } else { - error (EXIT_FAILURE, errno, "%s", errmsg); + die (EXIT_FAILURE, errno, "%s", errmsg); return false; } (*arg_ptr)++; /* consume the argument. */ @@ -2451,8 +2452,8 @@ parse_used (const struct parser_table* entry, char **argv, int *arg_ptr) } else { - error (EXIT_FAILURE, 0, - _("Invalid argument %s to -used"), offset_str); + die (EXIT_FAILURE, 0, + _("Invalid argument %s to -used"), offset_str); /*NOTREACHED*/ return false; } @@ -2492,15 +2493,15 @@ parse_user (const struct parser_table* entry, char **argv, int *arg_ptr) * not as helpful). */ if (username[0]) { - error (EXIT_FAILURE, 0, - _("%s is not the name of a known user"), - quotearg_n_style (0, options.err_quoting_style, - username)); + die (EXIT_FAILURE, 0, + _("%s is not the name of a known user"), + quotearg_n_style (0, options.err_quoting_style, + username)); } else { - error (EXIT_FAILURE, 0, - _("The argument to -user should not be empty")); + die (EXIT_FAILURE, 0, + _("The argument to -user should not be empty")); } /*NOTREACHED*/ return false; @@ -2593,8 +2594,8 @@ parse_context (const struct parser_table* entry, char **argv, int *arg_ptr) if (is_selinux_enabled () <= 0) { - error (EXIT_FAILURE, 0, - _("invalid predicate -context: SELinux is not enabled.")); + die (EXIT_FAILURE, 0, + _("invalid predicate -context: SELinux is not enabled.")); return false; } our_pred = insert_primary (entry, NULL); @@ -2657,9 +2658,9 @@ insert_type (char **argv, int *arg_ptr, if (!*typeletter) { - error (EXIT_FAILURE, 0, - _("Arguments to %s should contain at least one letter"), - pred_string); + die (EXIT_FAILURE, 0, + _("Arguments to %s should contain at least one letter"), + pred_string); /*NOTREACHED*/ return false; } @@ -2722,10 +2723,10 @@ insert_type (char **argv, int *arg_ptr, rate = 0.0311f; #else type_cell = 0; - error (EXIT_FAILURE, 0, - _("%s %c is not supported because symbolic links " - "are not supported on the platform find was compiled on."), - pred_string, (*typeletter)); + die (EXIT_FAILURE, 0, + _("%s %c is not supported because symbolic links " + "are not supported on the platform find was compiled on."), + pred_string, (*typeletter)); #endif break; case 'p': /* pipe */ @@ -2734,10 +2735,10 @@ insert_type (char **argv, int *arg_ptr, rate = 7.554e-6f; #else type_cell = 0; - error (EXIT_FAILURE, 0, - _("%s %c is not supported because FIFOs " - "are not supported on the platform find was compiled on."), - pred_string, (*typeletter)); + die (EXIT_FAILURE, 0, + _("%s %c is not supported because FIFOs " + "are not supported on the platform find was compiled on."), + pred_string, (*typeletter)); #endif break; case 's': /* socket */ @@ -2746,10 +2747,10 @@ insert_type (char **argv, int *arg_ptr, rate = 1.59e-5f; #else type_cell = 0; - error (EXIT_FAILURE, 0, - _("%s %c is not supported because named sockets " - "are not supported on the platform find was compiled on."), - pred_string, (*typeletter)); + die (EXIT_FAILURE, 0, + _("%s %c is not supported because named sockets " + "are not supported on the platform find was compiled on."), + pred_string, (*typeletter)); #endif break; case 'D': /* Solaris door */ @@ -2762,25 +2763,25 @@ insert_type (char **argv, int *arg_ptr, rate = 1.0e-5f; #else type_cell = 0; - error (EXIT_FAILURE, 0, - _("%s %c is not supported because Solaris doors " - "are not supported on the platform find was compiled on."), - pred_string, (*typeletter)); + die (EXIT_FAILURE, 0, + _("%s %c is not supported because Solaris doors " + "are not supported on the platform find was compiled on."), + pred_string, (*typeletter)); #endif break; default: /* None of the above ... nuke 'em. */ type_cell = 0; - error (EXIT_FAILURE, 0, - _("Unknown argument to %s: %c"), pred_string, (*typeletter)); + die (EXIT_FAILURE, 0, + _("Unknown argument to %s: %c"), pred_string, (*typeletter)); /*NOTREACHED*/ return false; } if (our_pred->args.types[type_cell]) { - error (EXIT_FAILURE, 0, - _("Duplicate file type '%c' in the argument list to %s."), - (*typeletter), pred_string); + die (EXIT_FAILURE, 0, + _("Duplicate file type '%c' in the argument list to %s."), + (*typeletter), pred_string); } our_pred->est_success_rate += rate; @@ -2794,19 +2795,19 @@ insert_type (char **argv, int *arg_ptr, { if (*typeletter != ',') { - error (EXIT_FAILURE, 0, - _("Must separate multiple arguments to %s using: ','"), - pred_string); + die (EXIT_FAILURE, 0, + _("Must separate multiple arguments to %s using: ','"), + pred_string); /*NOTREACHED*/ return false; } typeletter++; if (!*typeletter) { - error (EXIT_FAILURE, 0, - _("Last file type in list argument to %s " - "is missing, i.e., list is ending on: ','"), - pred_string); + die (EXIT_FAILURE, 0, + _("Last file type in list argument to %s " + "is missing, i.e., list is ending on: ','"), + pred_string); /*NOTREACHED*/ return false; } @@ -2862,25 +2863,25 @@ check_path_safety (const char *action) if (0 == len || (1 == len && path[pos] == '.')) { /* empty field signifies . */ - error (EXIT_FAILURE, 0, - _("The current directory is included in the PATH " - "environment variable, which is insecure in " - "combination with the %s action of find. " - "Please remove the current directory from your " - "$PATH (that is, remove \".\", doubled colons, " - "or leading or trailing colons)"), - action); + die (EXIT_FAILURE, 0, + _("The current directory is included in the PATH " + "environment variable, which is insecure in " + "combination with the %s action of find. " + "Please remove the current directory from your " + "$PATH (that is, remove \".\", doubled colons, " + "or leading or trailing colons)"), + action); } else if (path[pos] != '/') { char *relpath = strndup (&path[pos], len); - error (EXIT_FAILURE, 0, - _("The relative path %s is included in the PATH " - "environment variable, which is insecure in " - "combination with the %s action of find. " - "Please remove that entry from $PATH"), - safely_quote_err_filename (0, relpath ? relpath : &path[pos]), - action); + die (EXIT_FAILURE, 0, + _("The relative path %s is included in the PATH " + "environment variable, which is insecure in " + "combination with the %s action of find. " + "Please remove that entry from $PATH"), + safely_quote_err_filename (0, relpath ? relpath : &path[pos]), + action); /*NOTREACHED*/ free (relpath); } @@ -2983,10 +2984,10 @@ insert_exec_ok (const char *action, * allowed. We can specify this as those options are * not defined by POSIX. */ - error (EXIT_FAILURE, 0, - _("You may not use {} within the utility name for " - "-execdir and -okdir, because this is a potential " - "security problem.")); + die (EXIT_FAILURE, 0, + _("You may not use {} within the utility name for " + "-execdir and -okdir, because this is a potential " + "security problem.")); } } } @@ -3009,9 +3010,9 @@ insert_exec_ok (const char *action, if (brace_count > 1) { - error (EXIT_FAILURE, 0, - _("Only one instance of {} is supported with -exec%s ... +"), - suffix); + die (EXIT_FAILURE, 0, + _("Only one instance of {} is supported with -exec%s ... +"), + suffix); } else if (strlen (brace_arg) != 2u) { @@ -3019,11 +3020,11 @@ insert_exec_ok (const char *action, char buf[MsgBufSize]; const size_t needed = snprintf (buf, MsgBufSize, "-exec%s ... {} +", suffix); assert (needed <= MsgBufSize); /* If this assertion fails, correct the value of MsgBufSize. */ - error (EXIT_FAILURE, 0, - _("In %s the %s must appear by itself, but you specified %s"), - quotearg_n_style (0, options.err_quoting_style, buf), - quotearg_n_style (1, options.err_quoting_style, "{}"), - quotearg_n_style (2, options.err_quoting_style, brace_arg)); + die (EXIT_FAILURE, 0, + _("In %s the %s must appear by itself, but you specified %s"), + quotearg_n_style (0, options.err_quoting_style, buf), + quotearg_n_style (1, options.err_quoting_style, "{}"), + quotearg_n_style (2, options.err_quoting_style, brace_arg)); } } @@ -3039,8 +3040,7 @@ insert_exec_ok (const char *action, { case BC_INIT_ENV_TOO_BIG: case BC_INIT_CANNOT_ACCOMODATE_HEADROOM: - error (EXIT_FAILURE, 0, - _("The environment is too large for exec().")); + die (EXIT_FAILURE, 0, _("The environment is too large for exec().")); break; case BC_INIT_OK: /* Good news. Carry on. */ @@ -3166,7 +3166,7 @@ get_relative_timestamp (const char *str, if ((origin.tv_sec < result->ts.tv_sec) != (seconds < 0)) { /* an overflow has occurred. */ - error (EXIT_FAILURE, 0, overflowmessage, str); + die (EXIT_FAILURE, 0, overflowmessage, str); } result->ts.tv_nsec = origin.tv_nsec - nanosec; @@ -3232,8 +3232,8 @@ parse_time (const struct parser_table* entry, char *argv[], int *arg_ptr) origin.tv_sec += (DAYSECS-1); if (expected != (uintmax_t)origin.tv_sec) { - error (EXIT_FAILURE, 0, - _("arithmetic overflow when trying to calculate the end of today")); + die (EXIT_FAILURE, 0, + _("arithmetic overflow when trying to calculate the end of today")); } } } diff --git a/find/pred.c b/find/pred.c index c2d925c1..bd63a7bf 100644 --- a/find/pred.c +++ b/find/pred.c @@ -47,6 +47,7 @@ /* find headers. */ #include "defs.h" +#include "die.h" #include "dircallback.h" #include "listfile.h" #include "printquoted.h" @@ -766,7 +767,7 @@ is_ok (const char *program, const char *arg) /* XXX: printing UNTRUSTED data here. */ if (fprintf (stderr, _("< %s ... %s > ? "), program, arg) < 0) { - error (EXIT_FAILURE, errno, _("Failed to write prompt for -ok")); + die (EXIT_FAILURE, errno, _("Failed to write prompt for -ok")); } fflush (stderr); return yesno (); diff --git a/find/print.c b/find/print.c index b820333e..3a71e744 100644 --- a/find/print.c +++ b/find/print.c @@ -46,6 +46,7 @@ /* find-specific headers. */ #include "system.h" #include "defs.h" +#include "die.h" #include "print.h" #if ENABLE_NLS @@ -376,8 +377,8 @@ insert_fprintf (struct format_val *vec, if (fmt_editpos[1] == 0) { /* Trailing %. We don't like those. */ - error (EXIT_FAILURE, 0, - _("error: %s at end of format string"), fmt_editpos); + die (EXIT_FAILURE, 0, + _("error: %s at end of format string"), fmt_editpos); } if (fmt_editpos[1] == '%') /* %% produces just %. */ @@ -400,9 +401,9 @@ insert_fprintf (struct format_val *vec, { if (strchr ("{[(", fmt_editpos[0])) { - error (EXIT_FAILURE, 0, - _("error: the format directive `%%%c' is reserved for future use"), - (int)fmt_editpos[0]); + die (EXIT_FAILURE, 0, + _("error: the format directive `%%%c' is reserved for future use"), + (int)fmt_editpos[0]); /*NOTREACHED*/ } @@ -1263,7 +1264,7 @@ do_fprintf (struct format_val *dest, simply to ensure that the error message matches the one in insert_fprintf, easing the translation burden. */ - error (EXIT_FAILURE, 0, _("error: %s at end of format string"), "%"); + die (EXIT_FAILURE, 0, _("error: %s at end of format string"), "%"); /*NOTREACHED*/ break; } diff --git a/find/tree.c b/find/tree.c index d6b6a5dd..7e0beab2 100644 --- a/find/tree.c +++ b/find/tree.c @@ -30,6 +30,7 @@ /* find headers. */ #include "defs.h" +#include "die.h" #if ENABLE_NLS # include @@ -119,19 +120,19 @@ get_expr (struct predicate **input, struct predicate *this_pred = (*input); if (*input == NULL) - error (EXIT_FAILURE, 0, _("invalid expression")); + die (EXIT_FAILURE, 0, _("invalid expression")); switch ((*input)->p_type) { case NO_TYPE: - error (EXIT_FAILURE, 0, _("invalid expression")); + die (EXIT_FAILURE, 0, _("invalid expression")); break; case BI_OP: /* e.g. "find . -a" */ - error (EXIT_FAILURE, 0, - _("invalid expression; you have used a binary operator '%s' with nothing before it."), - this_pred->p_name); + die (EXIT_FAILURE, 0, + _("invalid expression; you have used a binary operator '%s' with nothing before it."), + this_pred->p_name); break; case CLOSE_PAREN: @@ -140,9 +141,9 @@ get_expr (struct predicate **input, && !this_pred->artificial) { /* e.g. "find \( -not \)" or "find \( -true -a \" */ - error (EXIT_FAILURE, 0, - _("expected an expression between '%s' and ')'"), - prev_pred->p_name); + die (EXIT_FAILURE, 0, + _("expected an expression between '%s' and ')'"), + prev_pred->p_name); } else if ( (*input)->artificial ) { @@ -150,13 +151,13 @@ get_expr (struct predicate **input, * unexpectedly. */ /* e.g. "find . -true -a" */ - error (EXIT_FAILURE, 0, - _("expected an expression after '%s'"), prev_pred->p_name); + die (EXIT_FAILURE, 0, + _("expected an expression after '%s'"), prev_pred->p_name); } else { - error (EXIT_FAILURE, 0, - _("invalid expression; you have too many ')'")); + die (EXIT_FAILURE, 0, + _("invalid expression; you have too many ')'")); } break; @@ -178,28 +179,30 @@ get_expr (struct predicate **input, * looking at is from the artificial "( ) -print" that we * add. */ - error (EXIT_FAILURE, 0, - _("invalid expression; expected to find a ')' but didn't see one. Perhaps you need an extra predicate after '%s'"), - this_pred->p_name); + die (EXIT_FAILURE, 0, + _("invalid expression; expected to find a ')' but didn't see one. " + "Perhaps you need an extra predicate after '%s'"), + this_pred->p_name); } prev_pred = (*input); *input = (*input)->pred_next; if ( (*input)->p_type == CLOSE_PAREN ) { - error (EXIT_FAILURE, 0, - _("invalid expression; empty parentheses are not allowed.")); + die (EXIT_FAILURE, 0, + _("invalid expression; empty parentheses are not allowed.")); } next = get_expr (input, NO_PREC, prev_pred); if ((*input == NULL) || ((*input)->p_type != CLOSE_PAREN)) - error (EXIT_FAILURE, 0, - _("invalid expression; I was expecting to find a ')' somewhere but did not see one.")); + die (EXIT_FAILURE, 0, + _("invalid expression; I was expecting to find a ')' somewhere " + "but did not see one.")); *input = (*input)->pred_next; /* move over close */ break; default: - error (EXIT_FAILURE, 0, _("oops -- invalid expression type!")); + die (EXIT_FAILURE, 0, _("oops -- invalid expression type!")); break; } @@ -214,7 +217,7 @@ get_expr (struct predicate **input, { next = scan_rest (input, next, prev_prec); if (next == NULL) - error (EXIT_FAILURE, 0, _("invalid expression")); + die (EXIT_FAILURE, 0, _("invalid expression")); } return (next); } @@ -253,7 +256,7 @@ scan_rest (struct predicate **input, /* I'm not sure how we get here, so it is not obvious what * sort of mistakes might give rise to this condition. */ - error (EXIT_FAILURE, 0, _("invalid expression")); + die (EXIT_FAILURE, 0, _("invalid expression")); break; case BI_OP: @@ -270,9 +273,9 @@ scan_rest (struct predicate **input, return tree; default: - error (EXIT_FAILURE, 0, - _("oops -- invalid expression type (%d)!"), - (int)(*input)->p_type); + die (EXIT_FAILURE, 0, + _("oops -- invalid expression type (%d)!"), + (int)(*input)->p_type); break; } } @@ -823,7 +826,7 @@ opt_expr (struct predicate **eval_treep) all of the user's parentheses. */ default: - error (EXIT_FAILURE, 0, _("oops -- invalid expression type!")); + die (EXIT_FAILURE, 0, _("oops -- invalid expression type!")); break; } @@ -1078,8 +1081,7 @@ get_pred_cost (const struct predicate *p) sizeof(costlookup[0]), cost_table_comparison)) { - error (EXIT_FAILURE, 0, - "failed to sort the costlookup array"); + die (EXIT_FAILURE, 0, "failed to sort the costlookup array"); } pred_table_sorted = 1; } @@ -1287,7 +1289,7 @@ build_expression_tree (int argc, char *argv[], int end_of_leading_options) if (parse_entry == NULL) { /* Command line option not recognized */ - error (EXIT_FAILURE, 0, _("unknown predicate `%s'"), predicate_name); + die (EXIT_FAILURE, 0, _("unknown predicate `%s'"), predicate_name); } /* We have recognised a test of the form -foo. Eat that, @@ -1307,18 +1309,18 @@ build_expression_tree (int argc, char *argv[], int end_of_leading_options) /* The special parse function spat out the * predicate. It must be invalid, or not tasty. */ - error (EXIT_FAILURE, 0, _("invalid predicate `%s'"), predicate_name); + die (EXIT_FAILURE, 0, _("invalid predicate `%s'"), predicate_name); } else { - error (EXIT_FAILURE, 0, _("invalid argument `%s' to `%s'"), - argv[i], predicate_name); + die (EXIT_FAILURE, 0, _("invalid argument `%s' to `%s'"), + argv[i], predicate_name); } } else { /* Command line option requires an argument */ - error (EXIT_FAILURE, 0, _("missing argument to `%s'"), predicate_name); + die (EXIT_FAILURE, 0, _("missing argument to `%s'"), predicate_name); } } else @@ -1394,15 +1396,15 @@ build_expression_tree (int argc, char *argv[], int end_of_leading_options) if (pred_is (cur_pred, pred_closeparen)) { /* e.g. "find \( -true \) \)" */ - error (EXIT_FAILURE, 0, _("you have too many ')'")); + die (EXIT_FAILURE, 0, _("you have too many ')'")); } else { if (cur_pred->p_name) - error (EXIT_FAILURE, 0, - _("unexpected extra predicate '%s'"), cur_pred->p_name); + die (EXIT_FAILURE, 0, + _("unexpected extra predicate '%s'"), cur_pred->p_name); else - error (EXIT_FAILURE, 0, _("unexpected extra predicate")); + die (EXIT_FAILURE, 0, _("unexpected extra predicate")); } } @@ -1523,7 +1525,7 @@ get_new_pred_chk_op (const struct parser_table *entry, switch (last_pred->p_type) { case NO_TYPE: - error (EXIT_FAILURE, 0, _("oops -- invalid default insertion of and!")); + die (EXIT_FAILURE, 0, _("oops -- invalid default insertion of and!")); break; case PRIMARY_TYPE: diff --git a/find/util.c b/find/util.c index 6182ae7b..5fd60cb9 100644 --- a/find/util.c +++ b/find/util.c @@ -41,6 +41,7 @@ /* find headers. */ #include "defs.h" +#include "die.h" #include "dircallback.h" #include "bugreports.h" @@ -492,10 +493,10 @@ record_initial_cwd (void) initial_wd = xmalloc (sizeof (*initial_wd)); if (0 != save_cwd (initial_wd)) { - error (EXIT_FAILURE, errno, - _("Failed to save initial working directory%s%s"), - (initial_wd->desc < 0 && initial_wd->name) ? ": " : "", - (initial_wd->desc < 0 && initial_wd->name) ? initial_wd->name : ""); + die (EXIT_FAILURE, errno, + _("Failed to save initial working directory%s%s"), + (initial_wd->desc < 0 && initial_wd->name) ? ": " : "", + (initial_wd->desc < 0 && initial_wd->name) ? initial_wd->name : ""); } } @@ -885,8 +886,8 @@ process_optimisation_option (const char *arg) { if (0 == arg[0]) { - error (EXIT_FAILURE, 0, - _("The -O option must be immediately followed by a decimal integer")); + die (EXIT_FAILURE, 0, + _("The -O option must be immediately followed by a decimal integer")); } else { @@ -895,8 +896,8 @@ process_optimisation_option (const char *arg) if (!isdigit ( (unsigned char) arg[0] )) { - error (EXIT_FAILURE, 0, - _("Please specify a decimal number immediately after -O")); + die (EXIT_FAILURE, 0, + _("Please specify a decimal number immediately after -O")); } else { @@ -906,29 +907,29 @@ process_optimisation_option (const char *arg) opt_level = strtoul (arg, &end, 10); if ( (0==opt_level) && (end==arg) ) { - error (EXIT_FAILURE, 0, - _("Please specify a decimal number immediately after -O")); + die (EXIT_FAILURE, 0, + _("Please specify a decimal number immediately after -O")); } else if (*end) { /* unwanted trailing characters. */ - error (EXIT_FAILURE, 0, _("Invalid optimisation level %s"), arg); + die (EXIT_FAILURE, 0, _("Invalid optimisation level %s"), arg); } else if ( (ULONG_MAX==opt_level) && errno) { - error (EXIT_FAILURE, errno, - _("Invalid optimisation level %s"), arg); + die (EXIT_FAILURE, errno, + _("Invalid optimisation level %s"), arg); } else if (opt_level > USHRT_MAX) { /* tricky to test, as on some platforms USHORT_MAX and ULONG_MAX * can have the same value, though this is unusual. */ - error (EXIT_FAILURE, 0, - _("Optimisation level %lu is too high. " - "If you want to find files very quickly, " - "consider using GNU locate."), - opt_level); + die (EXIT_FAILURE, 0, + _("Optimisation level %lu is too high. " + "If you want to find files very quickly, " + "consider using GNU locate."), + opt_level); } else { @@ -1073,8 +1074,10 @@ set_option_defaults (struct options *p) if (getenv ("FIND_BLOCK_SIZE")) { - error (EXIT_FAILURE, 0, - _("The environment variable FIND_BLOCK_SIZE is not supported, the only thing that affects the block size is the POSIXLY_CORRECT environment variable")); + die (EXIT_FAILURE, 0, + _("The environment variable FIND_BLOCK_SIZE is not supported, " + "the only thing that affects the block size is the " + "POSIXLY_CORRECT environment variable")); } #if LEAF_OPTIMISATION diff --git a/lib/buildcmd.c b/lib/buildcmd.c index d9afa267..996a4dc3 100644 --- a/lib/buildcmd.c +++ b/lib/buildcmd.c @@ -20,7 +20,6 @@ /* system headers. */ #include #include -#include #include #include #include @@ -39,6 +38,7 @@ /* find headers. */ #include "buildcmd.h" +#include "die.h" #if ENABLE_NLS # include @@ -150,7 +150,7 @@ bc_do_insert (struct buildcmd_control *ctl, } while (*arg); if (*arg) - error (EXIT_FAILURE, 0, _("command too long")); + die (EXIT_FAILURE, 0, _("command too long")); *p++ = '\0'; bc_push_arg (ctl, state, @@ -289,8 +289,8 @@ bc_do_exec (struct buildcmd_control *ctl, { /* No room to reduce the length of the argument list. Issue an error message and give up. */ - error (EXIT_FAILURE, 0, - _("can't call exec() due to argument size restrictions")); + die (EXIT_FAILURE, 0, + _("can't call exec() due to argument size restrictions")); } else { @@ -354,14 +354,14 @@ bc_push_arg (struct buildcmd_control *ctl, if (state->cmd_argv_chars + len + pfxlen > ctl->arg_max) { if (initial_args || state->cmd_argc == ctl->initial_argc) - error (EXIT_FAILURE, 0, - _("cannot fit single argument within argument list size limit")); + die (EXIT_FAILURE, 0, + _("cannot fit single argument within argument list size limit")); /* xargs option -i (replace_pat) implies -x (exit_if_size_exceeded) */ if (ctl->replace_pat || (ctl->exit_if_size_exceeded && (ctl->lines_per_exec || ctl->args_per_exec))) - error (EXIT_FAILURE, 0, _("argument list too long")); + die (EXIT_FAILURE, 0, _("argument list too long")); bc_do_exec (ctl, state); } if (bc_argc_limit_reached (initial_args, ctl, state)) @@ -617,10 +617,10 @@ exceeds (const char *env_var_name, size_t quantity) } else { - error (EXIT_FAILURE, errno, - _("Environment variable %s is not set to a " - "valid decimal number"), - env_var_name); + die (EXIT_FAILURE, errno, + _("Environment variable %s is not set to a " + "valid decimal number"), + env_var_name); return 0; } } diff --git a/lib/listfile.c b/lib/listfile.c index ff730691..452e93ab 100644 --- a/lib/listfile.c +++ b/lib/listfile.c @@ -44,6 +44,7 @@ #include "gettext.h" /* find headers. */ +#include "die.h" #include "listfile.h" /* Since major is a function on SVR4, we can't use `ifndef major'. */ @@ -457,7 +458,7 @@ list_file (const char *name, } if (!output_good) { - error (EXIT_FAILURE, errno, _("Failed to write output (at stage %d)"), failed_at); + die (EXIT_FAILURE, errno, _("Failed to write output (at stage %d)"), failed_at); } } diff --git a/lib/regextype.c b/lib/regextype.c index e5693532..8a7347dc 100644 --- a/lib/regextype.c +++ b/lib/regextype.c @@ -28,13 +28,15 @@ #include /* gnulib headers. */ -#include "error.h" #include "gettext.h" #include "quote.h" #include "regex.h" #include "regextype.h" #include "xalloc.h" +/* findutils headers */ +#include "die.h" + #if ENABLE_NLS # include @@ -100,10 +102,10 @@ get_regex_type (const char *s) p += sprintf (p, "%s", quote (regex_map[i].name)); } - error (EXIT_FAILURE, 0, - _("Unknown regular expression type %s; valid types are %s."), - quote (s), - buf); + die (EXIT_FAILURE, 0, + _("Unknown regular expression type %s; valid types are %s."), + quote (s), + buf); /*NOTREACHED*/ return -1; } diff --git a/lib/safe-atoi.c b/lib/safe-atoi.c index 2c6929ca..d80a1da6 100644 --- a/lib/safe-atoi.c +++ b/lib/safe-atoi.c @@ -23,11 +23,11 @@ #include /* gnulib headers. */ -#include "error.h" #include "gettext.h" #include "quotearg.h" /* find headers. */ +#include "die.h" #include "safe-atoi.h" #if ENABLE_NLS @@ -52,12 +52,12 @@ safe_atoi (const char *s, enum quoting_style style) if (errno == ERANGE) { /* too big, or too small. */ - error (EXIT_FAILURE, errno, "%s", s); + die (EXIT_FAILURE, errno, "%s", s); } else { /* not a valid number */ - error (EXIT_FAILURE, errno, "%s", s); + die (EXIT_FAILURE, errno, "%s", s); } /* Otherwise, we do a range chack against INT_MAX and INT_MIN * below. @@ -68,18 +68,18 @@ safe_atoi (const char *s, enum quoting_style style) { /* The number was in range for long, but not int. */ errno = ERANGE; - error (EXIT_FAILURE, errno, "%s", s); + die (EXIT_FAILURE, errno, "%s", s); } else if (*end) { - error (EXIT_FAILURE, errno, _("Unexpected suffix %s on %s"), - quotearg_n_style (0, style, end), - quotearg_n_style (1, style, s)); + die (EXIT_FAILURE, errno, _("Unexpected suffix %s on %s"), + quotearg_n_style (0, style, end), + quotearg_n_style (1, style, s)); } else if (end == s) { - error (EXIT_FAILURE, errno, _("Expected an integer: %s"), - quotearg_n_style (0, style, s)); + die (EXIT_FAILURE, errno, _("Expected an integer: %s"), + quotearg_n_style (0, style, s)); } return (int)lval; } diff --git a/locate/frcode.c b/locate/frcode.c index 109296c0..f0121268 100644 --- a/locate/frcode.c +++ b/locate/frcode.c @@ -84,10 +84,11 @@ #include "xalloc.h" /* find headers. */ -#include "findutils-version.h" #include "bugreports.h" -#include "locatedb.h" +#include "die.h" +#include "findutils-version.h" #include "gcc-function-attributes.h" +#include "locatedb.h" #if ENABLE_NLS # include @@ -173,24 +174,24 @@ get_seclevel (char *s) result = strtol (s, &p, 10); if ((0==result) && (p == optarg)) { - error (EXIT_FAILURE, 0, - _("You need to specify a security level as a decimal integer.")); + die (EXIT_FAILURE, 0, + _("You need to specify a security level as a decimal integer.")); /*NOTREACHED*/ return -1; } else if ((LONG_MIN==result || LONG_MAX==result) && errno) { - error (EXIT_FAILURE, 0, - _("Security level %s is outside the convertible range."), s); + die (EXIT_FAILURE, 0, + _("Security level %s is outside the convertible range."), s); /*NOTREACHED*/ return -1; } else if (*p) { /* Some suffix exists */ - error (EXIT_FAILURE, 0, - _("Security level %s has unexpected suffix %s."), s, p); + die (EXIT_FAILURE, 0, + _("Security level %s has unexpected suffix %s."), s, p); /*NOTREACHED*/ return -1; } @@ -204,7 +205,7 @@ static void outerr (void) { /* Issue the same error message as closeout () would. */ - error (EXIT_FAILURE, errno, _("write error")); + die (EXIT_FAILURE, errno, _("write error")); } int @@ -227,7 +228,7 @@ main (int argc, char **argv) if (atexit (close_stdout)) { - error (EXIT_FAILURE, errno, _("The atexit library function failed")); + die (EXIT_FAILURE, errno, _("The atexit library function failed")); } pathsize = oldpathsize = 1026; /* Increased as necessary by getline. */ @@ -250,9 +251,9 @@ main (int argc, char **argv) slocate_seclevel = get_seclevel (optarg); if (slocate_seclevel < 0 || slocate_seclevel > 1) { - error (EXIT_FAILURE, 0, - _("slocate security level %ld is unsupported."), - slocate_seclevel); + die (EXIT_FAILURE, 0, + _("slocate security level %ld is unsupported."), + slocate_seclevel); } break; @@ -287,7 +288,7 @@ main (int argc, char **argv) if (fwrite (LOCATEDB_MAGIC, 1, sizeof (LOCATEDB_MAGIC), stdout) != sizeof (LOCATEDB_MAGIC)) { - error (EXIT_FAILURE, errno, _("Failed to write to standard output")); + die (EXIT_FAILURE, errno, _("Failed to write to standard output")); } } diff --git a/locate/locate.c b/locate/locate.c index 2fce944d..4f081d18 100644 --- a/locate/locate.c +++ b/locate/locate.c @@ -94,12 +94,13 @@ #include "stat-time.h" /* find headers. */ +#include "bugreports.h" +#include "die.h" #include "findutils-version.h" +#include "gcc-function-attributes.h" #include "locatedb.h" #include "printquoted.h" -#include "bugreports.h" #include "splitstring.h" -#include "gcc-function-attributes.h" #if ENABLE_NLS @@ -176,8 +177,8 @@ set_max_db_age (const char *s) if (0 == *s) { - error (EXIT_FAILURE, 0, - _("The argument for option --max-database-age must not be empty")); + die (EXIT_FAILURE, 0, + _("The argument for option --max-database-age must not be empty")); } @@ -192,16 +193,16 @@ set_max_db_age (const char *s) if ((ULONG_MAX == val && ERANGE == errno) || (0 == val && EINVAL == errno)) { - error (EXIT_FAILURE, errno, - _("Invalid argument %s for option --max-database-age"), - quotearg_n_style (0, locale_quoting_style, s)); + die (EXIT_FAILURE, errno, + _("Invalid argument %s for option --max-database-age"), + quotearg_n_style (0, locale_quoting_style, s)); } else if (*end) { /* errno wasn't set, don't print its message */ - error (EXIT_FAILURE, 0, - _("Invalid argument %s for option --max-database-age"), - quotearg_n_style (0, locale_quoting_style, s)); + die (EXIT_FAILURE, 0, + _("Invalid argument %s for option --max-database-age"), + quotearg_n_style (0, locale_quoting_style, s)); } else { @@ -449,10 +450,10 @@ visit_justprint_unquoted (struct process_data *procdata, void *context) static void toolong (struct process_data *procdata) { - error (EXIT_FAILURE, 0, - _("locate database %s contains a " - "filename longer than locate can handle"), - procdata->dbfile); + die (EXIT_FAILURE, 0, + _("locate database %s contains a " + "filename longer than locate can handle"), + procdata->dbfile); } static void @@ -561,8 +562,8 @@ visit_locate02_format (struct process_data *procdata, void *context) * reading in data which is outside our control, we * cannot prevent it. */ - error (EXIT_FAILURE, 0, _("locate database %s is corrupt or invalid"), - quotearg_n_style (0, locale_quoting_style, procdata->dbfile)); + die (EXIT_FAILURE, 0, _("locate database %s is corrupt or invalid"), + quotearg_n_style (0, locale_quoting_style, procdata->dbfile)); } /* Overlay the old path with the remainder of the new. */ @@ -1162,10 +1163,10 @@ search_one_database (int argc, 256 - nread, procdata.fp); if ( (more_read + nread) != 256 ) { - error (EXIT_FAILURE, 0, - _("Old-format locate database %s is " - "too short to be valid"), - quotearg_n_style (0, locale_quoting_style, dbfile)); + die (EXIT_FAILURE, 0, + _("Old-format locate database %s is " + "too short to be valid"), + quotearg_n_style (0, locale_quoting_style, dbfile)); } } @@ -1207,7 +1208,7 @@ search_one_database (int argc, &p->regex); if (error_message) { - error (EXIT_FAILURE, 0, "%s", error_message); + die (EXIT_FAILURE, 0, "%s", error_message); } else { @@ -1510,8 +1511,8 @@ drop_privs (void) return 0; fail: - error (EXIT_FAILURE, errno, "%s", - quotearg_n_style (0, locale_quoting_style, what)); + die (EXIT_FAILURE, errno, "%s", + quotearg_n_style (0, locale_quoting_style, what)); abort (); kill (0, SIGKILL); _exit (1); @@ -1585,7 +1586,7 @@ dolocate (int argc, char **argv, int secure_db_fd) quote_opts = clone_quoting_options (NULL); if (atexit (close_stdout) || atexit (cleanup_quote_opts)) { - error (EXIT_FAILURE, errno, _("The atexit library function failed")); + die (EXIT_FAILURE, errno, _("The atexit library function failed")); } limits.limit = 0; diff --git a/locate/word_io.c b/locate/word_io.c index bc5f4ad8..51be32c3 100644 --- a/locate/word_io.c +++ b/locate/word_io.c @@ -32,6 +32,7 @@ #include "quotearg.h" /* find headers. */ +#include "die.h" #include "locatedb.h" #if ENABLE_NLS @@ -128,10 +129,10 @@ getword (FILE *fp, * Either condition is fatal. */ if (feof (fp)) - error (EXIT_FAILURE, 0, _("unexpected EOF in %s"), quoted_name); + die (EXIT_FAILURE, 0, _("unexpected EOF in %s"), quoted_name); else - error (EXIT_FAILURE, errno, - _("error reading a word from %s"), quoted_name); + die (EXIT_FAILURE, errno, + _("error reading a word from %s"), quoted_name); abort (); } else diff --git a/xargs/xargs.c b/xargs/xargs.c index 8ef91dee..c07d92a9 100644 --- a/xargs/xargs.c +++ b/xargs/xargs.c @@ -258,9 +258,9 @@ get_char_oct_or_hex_escape (const char *s) else { p = NULL; /* Silence compiler warning. */ - error (EXIT_FAILURE, 0, - _("Invalid escape sequence %s in input delimiter specification."), - s); + die (EXIT_FAILURE, 0, + _("Invalid escape sequence %s in input delimiter specification."), + s); } errno = 0; endp = NULL; @@ -276,24 +276,27 @@ get_char_oct_or_hex_escape (const char *s) { if (16 == base) { - error (EXIT_FAILURE, 0, - _("Invalid escape sequence %s in input delimiter specification; character values must not exceed %lx."), - s, (unsigned long)UCHAR_MAX); + die (EXIT_FAILURE, 0, + _("Invalid escape sequence %s in input delimiter specification; " + "character values must not exceed %lx."), + s, (unsigned long)UCHAR_MAX); } else { - error (EXIT_FAILURE, 0, - _("Invalid escape sequence %s in input delimiter specification; character values must not exceed %lo."), - s, (unsigned long)UCHAR_MAX); + die (EXIT_FAILURE, 0, + _("Invalid escape sequence %s in input delimiter specification; " + "character values must not exceed %lo."), + s, (unsigned long)UCHAR_MAX); } } /* check for trailing garbage */ if (0 != *endp) { - error (EXIT_FAILURE, 0, - _("Invalid escape sequence %s in input delimiter specification; trailing characters %s not recognised."), - s, endp); + die (EXIT_FAILURE, 0, + _("Invalid escape sequence %s in input delimiter specification; " + "trailing characters %s not recognised."), + s, endp); } return (char) val; @@ -336,9 +339,11 @@ get_input_delimiter (const char *s) } else { - error (EXIT_FAILURE, 0, - _("Invalid input delimiter specification %s: the delimiter must be either a single character or an escape sequence starting with \\."), - s); + die (EXIT_FAILURE, 0, + _("Invalid input delimiter specification %s: the delimiter must " + "be either a single character or an escape sequence starting " + "with \\."), + s); /*NOTREACHED*/ return 0; } @@ -354,7 +359,7 @@ noop (void) static void fail_due_to_env_size (void) { - error (EXIT_FAILURE, 0, _("environment is too large for exec")); + die (EXIT_FAILURE, 0, _("environment is too large for exec")); } static size_t @@ -426,7 +431,7 @@ main (int argc, char **argv) if (atexit (close_stdin) || atexit (wait_for_proc_all)) { - error (EXIT_FAILURE, errno, _("The atexit library function failed")); + die (EXIT_FAILURE, errno, _("The atexit library function failed")); } /* xargs is required by POSIX to allow 2048 bytes of headroom @@ -642,9 +647,9 @@ main (int argc, char **argv) case PROCESS_SLOT_VAR: if (strchr (optarg, '=')) { - error (EXIT_FAILURE, 0, - _("option --%s may not be set to a value which includes `='"), - longopts[option_index].name); + die (EXIT_FAILURE, 0, + _("option --%s may not be set to a value which includes `='"), + longopts[option_index].name); } slot_var_name = optarg; if (0 != unsetenv (slot_var_name)) @@ -654,9 +659,9 @@ main (int argc, char **argv) have the same value for this variable; see set_slot_var. */ - error (EXIT_FAILURE, errno, - _("failed to unset environment variable %s"), - slot_var_name); + die (EXIT_FAILURE, errno, + _("failed to unset environment variable %s"), + slot_var_name); } break; @@ -711,9 +716,9 @@ main (int argc, char **argv) input_stream = fopen_cloexec_for_read_only (input_file); if (NULL == input_stream) { - error (EXIT_FAILURE, errno, - _("Cannot open input file %s"), - quotearg_n_style (0, locale_quoting_style, input_file)); + die (EXIT_FAILURE, errno, + _("Cannot open input file %s"), + quotearg_n_style (0, locale_quoting_style, input_file)); } } @@ -888,8 +893,10 @@ read_line (void) if (state == QUOTE) { exec_if_possible (); - error (EXIT_FAILURE, 0, _("unmatched %s quote; by default quotes are special to xargs unless you use the -0 option"), - quotc == '"' ? _("double") : _("single")); + die (EXIT_FAILURE, 0, + _("unmatched %s quote; by default quotes are special to " + "xargs unless you use the -0 option"), + quotc == '"' ? _("double") : _("single")); } if (first && EOF_STR (linebuf)) return -1; @@ -981,8 +988,10 @@ read_line (void) if (c == '\n') { exec_if_possible (); - error (EXIT_FAILURE, 0, _("unmatched %s quote; by default quotes are special to xargs unless you use the -0 option"), - quotc == '"' ? _("double") : _("single")); + die (EXIT_FAILURE, 0, + _("unmatched %s quote; by default quotes are special to " + "xargs unless you use the -0 option"), + quotc == '"' ? _("double") : _("single")); } if (c == quotc) { @@ -1011,7 +1020,7 @@ read_line (void) if (p >= endbuf) { exec_if_possible (); - error (EXIT_FAILURE, 0, _("argument line too long")); + die (EXIT_FAILURE, 0, _("argument line too long")); } *p++ = c; #else @@ -1076,7 +1085,7 @@ read_string (void) if (p >= endbuf) { exec_if_possible (); - error (EXIT_FAILURE, 0, _("argument line too long")); + die (EXIT_FAILURE, 0, _("argument line too long")); } *p++ = c; } @@ -1095,7 +1104,7 @@ print_args (bool ask) for (i = 0; i < bc_state.cmd_argc - 1; i++) { if (fprintf (stderr, "%s ", bc_state.cmd_argv[i]) < 0) - error (EXIT_FAILURE, errno, _("Failed to write to stderr")); + die (EXIT_FAILURE, errno, _("Failed to write to stderr")); } if (ask) @@ -1107,18 +1116,18 @@ print_args (bool ask) { tty_stream = fopen_cloexec_for_read_only ("/dev/tty"); if (!tty_stream) - error (EXIT_FAILURE, errno, - _("failed to open /dev/tty for reading")); + die (EXIT_FAILURE, errno, + _("failed to open /dev/tty for reading")); } fputs ("?...", stderr); if (fflush (stderr) != 0) - error (EXIT_FAILURE, errno, _("Failed to write to stderr")); + die (EXIT_FAILURE, errno, _("Failed to write to stderr")); c = savec = getc (tty_stream); while (c != EOF && c != '\n') c = getc (tty_stream); if (EOF == c) - error (EXIT_FAILURE, errno, _("Failed to read from stdin")); + die (EXIT_FAILURE, errno, _("Failed to read from stdin")); if (savec == 'y' || savec == 'Y') return true; } @@ -1208,14 +1217,22 @@ prep_child_for_exec (void) * stdin is almost as good as executing it * with its stdin attached to /dev/null. */ - error (open_tty ? EXIT_FAILURE : 0, errno, "%s", - quotearg_n_style (0, locale_quoting_style, inputfile)); + if (open_tty) + { + die (EXIT_FAILURE, errno, "%s", + quotearg_n_style (0, locale_quoting_style, inputfile)); + } + else + { + error (0, errno, "%s", + quotearg_n_style (0, locale_quoting_style, inputfile)); + } } if (STDIN_FILENO < fd) { if (dup2(fd, STDIN_FILENO) != 0) - error (EXIT_FAILURE, errno, - _("failed to redirect standard input of the child process")); + die (EXIT_FAILURE, errno, + _("failed to redirect standard input of the child process")); close(fd); } } @@ -1267,7 +1284,7 @@ xargs_do_exec (struct buildcmd_control *ctl, void *usercontext, int argc, char * wait_for_proc (false, 0u); if (pipe (fd)) - error (EXIT_FAILURE, errno, _("could not create pipe before fork")); + die (EXIT_FAILURE, errno, _("could not create pipe before fork")); fcntl (fd[1], F_SETFD, FD_CLOEXEC); /* If we run out of processes, wait for a child to return and @@ -1390,9 +1407,9 @@ xargs_do_exec (struct buildcmd_control *ctl, void *usercontext, int argc, char * } default: { - error (EXIT_FAILURE, errno, - _("read returned unexpected value %zu; " - "this is probably a bug, please report it"), r); + die (EXIT_FAILURE, errno, + _("read returned unexpected value %zu; " + "this is probably a bug, please report it"), r); } } /* switch on bytes read */ close (fd[0]); @@ -1483,8 +1500,8 @@ wait_for_proc (bool all, unsigned int minreap) while ((pid = waitpid (-1, &status, wflags)) == (pid_t) -1) { if (errno != EINTR) - error (EXIT_FAILURE, errno, - _("error waiting for child process")); + die (EXIT_FAILURE, errno, + _("error waiting for child process")); if (stop_waiting && !all) { -- 2.15.0