exit 1; } \
|| :
+# 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:
+ @cd $(srcdir)/src && GIT_PAGER= git grep -E \
+ 'error \(.*_(FAILURE|INVALID)' \
+ && { echo '$(ME): '"Use die() instead of error" 1>&2; \
+ exit 1; } \
+ || :
+
# Avoid unstyled quoting to internal slots and thus destined for diagnostics
# as that can leak unescaped control characters to the output, when using
# the default "literal" quoting style.
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "quote.h"
{
/* Simple write. */
if (fwrite (buffer, 1, len, stdout) < len)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
}
else
for (written = 0; written < len;)
if (to_write == 0)
{
if (fputc ('\n', out) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
*current_column = 0;
}
else
{
if (fwrite (buffer + written, 1, to_write, stdout) < to_write)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
*current_column += to_write;
written += to_write;
}
/* When wrapping, terminate last line. */
if (wrap_column && current_column > 0 && fputc ('\n', out) == EOF)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
if (ferror (in))
- error (EXIT_FAILURE, errno, _("read error"));
+ die (EXIT_FAILURE, errno, _("read error"));
}
static void
sum += n;
if (ferror (in))
- error (EXIT_FAILURE, errno, _("read error"));
+ die (EXIT_FAILURE, errno, _("read error"));
}
while (sum < BASE_LENGTH (DEC_BLOCKSIZE) && !feof (in));
ok = base_decode_ctx (&ctx, inbuf, (k == 0 ? sum : 0), outbuf, &n);
if (fwrite (outbuf, 1, n, out) < n)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
if (!ok)
- error (EXIT_FAILURE, 0, _("invalid input"));
+ die (EXIT_FAILURE, 0, _("invalid input"));
}
}
while (!feof (in));
{
input_fh = fopen (infile, "rb");
if (input_fh == NULL)
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
}
fadvise (input_fh, FADVISE_SEQUENTIAL);
if (fclose (input_fh) == EOF)
{
if (STREQ (infile, "-"))
- error (EXIT_FAILURE, errno, _("closing standard input"));
+ die (EXIT_FAILURE, errno, _("closing standard input"));
else
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
}
return EXIT_SUCCESS;
#include "system.h"
#include "ioblksize.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "full-write.h"
/* The following is ok, since we know that 0 < n_read. */
size_t n = n_read;
if (full_write (STDOUT_FILENO, buf, n) != n)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
}
}
}
if (0 < n_write)
{
if (full_write (STDOUT_FILENO, outbuf, n_write) != n_write)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
*bpout = outbuf;
}
}
do
{
if (full_write (STDOUT_FILENO, wp, outsize) != outsize)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
wp += outsize;
remaining_bytes = bpout - wp;
}
/* Get device, i-node number, and optimal blocksize of output. */
if (fstat (STDOUT_FILENO, &stat_buf) < 0)
- error (EXIT_FAILURE, errno, _("standard output"));
+ die (EXIT_FAILURE, errno, _("standard output"));
outsize = io_blksize (stat_buf);
out_dev = stat_buf.st_dev;
while (++argind < argc);
if (have_read_stdin && close (STDIN_FILENO) < 0)
- error (EXIT_FAILURE, errno, _("closing standard input"));
+ die (EXIT_FAILURE, errno, _("closing standard input"));
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
#include "system.h"
#include "dev-ino.h"
+#include "die.h"
#include "error.h"
#include "ignore-value.h"
#include "quote.h"
if (bit_flags == FTS_PHYSICAL)
{
if (dereference == 1)
- error (EXIT_FAILURE, 0,
- _("-R --dereference requires either -H or -L"));
+ die (EXIT_FAILURE, 0,
+ _("-R --dereference requires either -H or -L"));
affect_symlink_referent = false;
}
else
{
if (dereference == 0)
- error (EXIT_FAILURE, 0, _("-R -h requires -P"));
+ die (EXIT_FAILURE, 0, _("-R -h requires -P"));
affect_symlink_referent = true;
}
}
char *ref_context = NULL;
if (getfilecon (reference_file, &ref_context) < 0)
- error (EXIT_FAILURE, errno, _("failed to get security context of %s"),
- quoteaf (reference_file));
+ die (EXIT_FAILURE, errno, _("failed to get security context of %s"),
+ quoteaf (reference_file));
specified_context = ref_context;
}
{
specified_context = argv[optind++];
if (security_check_context (se_const (specified_context)) < 0)
- error (EXIT_FAILURE, errno, _("invalid context: %s"),
- quote (specified_context));
+ die (EXIT_FAILURE, errno, _("invalid context: %s"),
+ quote (specified_context));
}
if (reference_file && component_specified)
static struct dev_ino dev_ino_buf;
root_dev_ino = get_root_dev_ino (&dev_ino_buf);
if (root_dev_ino == NULL)
- error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
- quoteaf ("/"));
+ die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
+ quoteaf ("/"));
}
else
{
#include "system.h"
#include "chown-core.h"
+#include "die.h"
#include "error.h"
#include "fts_.h"
#include "quote.h"
unsigned long int tmp;
if (! (xstrtoul (name, NULL, 10, &tmp, "") == LONGINT_OK
&& tmp <= GID_T_MAX))
- error (EXIT_FAILURE, 0, _("invalid group: %s"),
- quote (name));
+ die (EXIT_FAILURE, 0, _("invalid group: %s"),
+ quote (name));
gid = tmp;
}
endgrent (); /* Save a file descriptor. */
if (bit_flags == FTS_PHYSICAL)
{
if (dereference == 1)
- error (EXIT_FAILURE, 0,
- _("-R --dereference requires either -H or -L"));
+ die (EXIT_FAILURE, 0,
+ _("-R --dereference requires either -H or -L"));
dereference = 0;
}
}
{
struct stat ref_stats;
if (stat (reference_file, &ref_stats))
- error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
- quoteaf (reference_file));
+ die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
+ quoteaf (reference_file));
gid = ref_stats.st_gid;
chopt.group_name = gid_to_name (ref_stats.st_gid);
static struct dev_ino dev_ino_buf;
chopt.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
if (chopt.root_dev_ino == NULL)
- error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
- quoteaf ("/"));
+ die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
+ quoteaf ("/"));
}
bit_flags |= FTS_DEFER_STAT;
#include "system.h"
#include "dev-ino.h"
+#include "die.h"
#include "error.h"
#include "filemode.h"
#include "ignore-value.h"
{
change = mode_create_from_ref (reference_file);
if (!change)
- error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
- quoteaf (reference_file));
+ die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
+ quoteaf (reference_file));
}
else
{
static struct dev_ino dev_ino_buf;
root_dev_ino = get_root_dev_ino (&dev_ino_buf);
if (root_dev_ino == NULL)
- error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
- quoteaf ("/"));
+ die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
+ quoteaf ("/"));
}
else
{
#include "system.h"
#include "chown-core.h"
+#include "die.h"
#include "error.h"
#include "fts_.h"
#include "quote.h"
&required_uid, &required_gid,
NULL, NULL);
if (e)
- error (EXIT_FAILURE, 0, "%s: %s", e, quote (optarg));
+ die (EXIT_FAILURE, 0, "%s: %s", e, quote (optarg));
break;
}
if (bit_flags == FTS_PHYSICAL)
{
if (dereference == 1)
- error (EXIT_FAILURE, 0,
- _("-R --dereference requires either -H or -L"));
+ die (EXIT_FAILURE, 0,
+ _("-R --dereference requires either -H or -L"));
dereference = 0;
}
}
{
struct stat ref_stats;
if (stat (reference_file, &ref_stats))
- error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
- quoteaf (reference_file));
+ die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
+ quoteaf (reference_file));
uid = ref_stats.st_uid;
gid = ref_stats.st_gid;
const char *e = parse_user_spec (argv[optind], &uid, &gid,
&chopt.user_name, &chopt.group_name);
if (e)
- error (EXIT_FAILURE, 0, "%s: %s", e, quote (argv[optind]));
+ die (EXIT_FAILURE, 0, "%s: %s", e, quote (argv[optind]));
/* If a group is specified but no user, set the user name to the
empty string so that diagnostics say "ownership :GROUP"
static struct dev_ino dev_ino_buf;
chopt.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
if (chopt.root_dev_ino == NULL)
- error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
- quoteaf ("/"));
+ die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
+ quoteaf ("/"));
}
bit_flags |= FTS_DEFER_STAT;
#include <grp.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "ignore-value.h"
#include "mgetgroups.h"
}
if (chroot (newroot) != 0)
- error (EXIT_CANCELED, errno, _("cannot change root directory to %s"),
- quoteaf (newroot));
+ die (EXIT_CANCELED, errno, _("cannot change root directory to %s"),
+ quoteaf (newroot));
if (! skip_chdir && chdir ("/"))
- error (EXIT_CANCELED, errno, _("cannot chdir to root directory"));
+ die (EXIT_CANCELED, errno, _("cannot chdir to root directory"));
if (argc == optind + 1)
{
char const *err = parse_user_spec (userspec, &uid, &gid, NULL, NULL);
if (err && uid_unset (uid) && gid_unset (gid))
- error (EXIT_CANCELED, errno, "%s", (err));
+ die (EXIT_CANCELED, errno, "%s", (err));
}
/* If no gid is supplied or looked up, do so now.
}
else if (gid_unset (gid))
{
- error (EXIT_CANCELED, errno,
- _("no group specified for unknown uid: %d"), (int) uid);
+ die (EXIT_CANCELED, errno,
+ _("no group specified for unknown uid: %d"), (int) uid);
}
}
if (ngroups <= 0)
{
if (! n_gids)
- error (EXIT_CANCELED, errno,
- _("failed to get supplemental groups"));
+ die (EXIT_CANCELED, errno,
+ _("failed to get supplemental groups"));
/* else look-up outside the chroot worked, then go with those. */
}
else
#endif
if ((uid_set (uid) || groups) && setgroups (n_gids, gids) != 0)
- error (EXIT_CANCELED, errno, _("failed to set supplemental groups"));
+ die (EXIT_CANCELED, errno, _("failed to set supplemental groups"));
free (in_gids);
free (out_gids);
if (gid_set (gid) && setgid (gid))
- error (EXIT_CANCELED, errno, _("failed to set group-ID"));
+ die (EXIT_CANCELED, errno, _("failed to set group-ID"));
if (uid_set (uid) && setuid (uid))
- error (EXIT_CANCELED, errno, _("failed to set user-ID"));
+ die (EXIT_CANCELED, errno, _("failed to set user-ID"));
/* Execute the given command. */
execvp (argv[0], argv);
# include <getopt.h>
# include "long-options.h"
+# include "die.h"
# include "error.h"
/* Number of bytes to read at once. */
unsigned char *cp = buf;
if (length + bytes_read < length)
- error (EXIT_FAILURE, 0, _("%s: file too long"), quotef (file));
+ die (EXIT_FAILURE, 0, _("%s: file too long"), quotef (file));
length += bytes_read;
while (bytes_read--)
crc = (crc << 8) ^ crctab[((crc >> 24) ^ *cp++) & 0xFF];
printf ("%u %s\n", (unsigned int) crc, hp);
if (ferror (stdout))
- error (EXIT_FAILURE, errno, "-: %s", _("write error"));
+ die (EXIT_FAILURE, errno, "-: %s", _("write error"));
return true;
}
}
if (have_read_stdin && fclose (stdin) == EOF)
- error (EXIT_FAILURE, errno, "-");
+ die (EXIT_FAILURE, errno, "-");
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
#include <sys/types.h>
#include "system.h"
#include "linebuffer.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "hard-locale.h"
alt[i][2] = 0;
streams[i] = (STREQ (infiles[i], "-") ? stdin : fopen (infiles[i], "r"));
if (!streams[i])
- error (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
+ die (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
fadvise (streams[i], FADVISE_SEQUENTIAL);
thisline[i] = readlinebuffer_delim (all_line[i][alt[i][0]], streams[i],
delim);
if (ferror (streams[i]))
- error (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
+ die (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
}
while (thisline[0] || thisline[1])
all_line[i][alt[i][1]], i + 1);
if (ferror (streams[i]))
- error (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
+ die (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
fill_up[i] = false;
}
for (i = 0; i < 2; i++)
if (fclose (streams[i]) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
+ die (EXIT_FAILURE, errno, "%s", quotef (infiles[i]));
}
int
case OUTPUT_DELIMITER_OPTION:
if (col_sep_len && !STREQ (col_sep, optarg))
- error (EXIT_FAILURE, 0, _("multiple output delimiters specified"));
+ die (EXIT_FAILURE, 0, _("multiple output delimiters specified"));
col_sep = optarg;
col_sep_len = *optarg ? strlen (optarg) : 1;
break;
#include "copy.h"
#include "cp-hash.h"
#include "extent-scan.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "fcntl--.h"
restore_default_fscreatecon_or_die (void)
{
if (setfscreatecon (NULL) != 0)
- error (EXIT_FAILURE, errno,
- _("failed to restore the default file creation context"));
+ die (EXIT_FAILURE, errno,
+ _("failed to restore the default file creation context"));
}
/* Create a hard link DST_NAME to SRC_NAME, honoring the REPLACE, VERBOSE and
#endif
#include "system.h"
+#include "die.h"
#include "error.h"
#include "quote.h"
{
argv[nskip] = arg_name; /* XXX: Discards any specified path. */
launch_program (prog_name, argc - nskip, argv + nskip);
- error (EXIT_FAILURE, 0, _("unknown program %s"),
- quote (prog_name));
+ die (EXIT_FAILURE, 0, _("unknown program %s"),
+ quote (prog_name));
}
}
#include "backupfile.h"
#include "copy.h"
#include "cp-hash.h"
+#include "die.h"
#include "error.h"
#include "filenamecat.h"
#include "ignore-value.h"
if (err)
{
if (err != ENOENT)
- error (EXIT_FAILURE, err, _("failed to access %s"), quoteaf (file));
+ die (EXIT_FAILURE, err, _("failed to access %s"), quoteaf (file));
*new_dst = true;
}
return is_a_dir;
if (no_target_directory)
{
if (target_directory)
- error (EXIT_FAILURE, 0,
- _("cannot combine --target-directory (-t) "
- "and --no-target-directory (-T)"));
+ die (EXIT_FAILURE, 0,
+ _("cannot combine --target-directory (-t) "
+ "and --no-target-directory (-T)"));
if (2 < n_files)
{
error (0, 0, _("extra operand %s"), quoteaf (file[2]));
&& target_directory_operand (file[n_files - 1], &sb, &new_dst))
target_directory = file[--n_files];
else if (2 < n_files)
- error (EXIT_FAILURE, 0, _("target %s is not a directory"),
- quoteaf (file[n_files - 1]));
+ die (EXIT_FAILURE, 0, _("target %s is not a directory"),
+ quoteaf (file[n_files - 1]));
}
if (target_directory)
case 't':
if (target_directory)
- error (EXIT_FAILURE, 0,
- _("multiple target directories specified"));
+ die (EXIT_FAILURE, 0,
+ _("multiple target directories specified"));
else
{
struct stat st;
if (stat (optarg, &st) != 0)
- error (EXIT_FAILURE, errno, _("failed to access %s"),
- quoteaf (optarg));
+ die (EXIT_FAILURE, errno, _("failed to access %s"),
+ quoteaf (optarg));
if (! S_ISDIR (st.st_mode))
- error (EXIT_FAILURE, 0, _("target %s is not a directory"),
- quoteaf (optarg));
+ die (EXIT_FAILURE, 0, _("target %s is not a directory"),
+ quoteaf (optarg));
}
target_directory = optarg;
break;
x.preserve_security_context = false;
if (x.preserve_security_context && (x.set_security_context || scontext))
- error (EXIT_FAILURE, 0,
- _("cannot set target context and preserve it"));
+ die (EXIT_FAILURE, 0,
+ _("cannot set target context and preserve it"));
if (x.require_preserve_context && ! selinux_enabled)
- error (EXIT_FAILURE, 0,
- _("cannot preserve security context "
- "without an SELinux-enabled kernel"));
+ die (EXIT_FAILURE, 0,
+ _("cannot preserve security context "
+ "without an SELinux-enabled kernel"));
/* FIXME: This handles new files. But what about existing files?
I.e., if updating a tree, new files would have the specified context,
restorecon (dst_path, 0, true);
*/
if (scontext && setfscreatecon (se_const (scontext)) < 0)
- error (EXIT_FAILURE, errno,
- _("failed to set default file creation context to %s"),
- quote (scontext));
+ die (EXIT_FAILURE, errno,
+ _("failed to set default file creation context to %s"),
+ quote (scontext));
#if !USE_XATTR
if (x.require_preserve_xattr)
- error (EXIT_FAILURE, 0, _("cannot preserve extended attributes, cp is "
- "built without xattr support"));
+ die (EXIT_FAILURE, 0, _("cannot preserve extended attributes, cp is "
+ "built without xattr support"));
#endif
/* Allocate space for remembering copied and created files. */
get_first_line_in_buffer (void)
{
if (head == NULL && !load_buffer ())
- error (EXIT_FAILURE, errno, _("input disappeared"));
+ die (EXIT_FAILURE, errno, _("input disappeared"));
return head->first_available;
}
set_input_file (const char *name)
{
if (! STREQ (name, "-") && fd_reopen (STDIN_FILENO, name, O_RDONLY, 0) < 0)
- error (EXIT_FAILURE, errno, _("cannot open %s for reading"),
- quoteaf (name));
+ die (EXIT_FAILURE, errno, _("cannot open %s for reading"),
+ quoteaf (name));
}
/* Write all lines from the beginning of the buffer up to, but
check_for_offset (struct control *p, const char *str, const char *num)
{
if (xstrtoimax (num, NULL, 10, &p->offset, "") != LONGINT_OK)
- error (EXIT_FAILURE, 0, _("%s: integer expected after delimiter"),
- quote (str));
+ die (EXIT_FAILURE, 0, _("%s: integer expected after delimiter"),
+ quote (str));
}
/* Given that the first character of command line arg STR is '{',
end = str + strlen (str) - 1;
if (*end != '}')
- error (EXIT_FAILURE, 0, _("%s: '}' is required in repeat count"),
- quote (str));
+ die (EXIT_FAILURE, 0, _("%s: '}' is required in repeat count"),
+ quote (str));
*end = '\0';
if (str+1 == end-1 && *(str+1) == '*')
{
if (xstrtoumax (str + 1, NULL, 10, &val, "") != LONGINT_OK)
{
- error (EXIT_FAILURE, 0,
- _("%s}: integer required between '{' and '}'"),
- quote (global_argv[argnum]));
+ die (EXIT_FAILURE, 0,
+ _("%s}: integer required between '{' and '}'"),
+ quote (global_argv[argnum]));
}
p->repeat = val;
}
closing_delim = strrchr (str + 1, delim);
if (closing_delim == NULL)
- error (EXIT_FAILURE, 0,
- _("%s: closing delimiter '%c' missing"), str, delim);
+ die (EXIT_FAILURE, 0,
+ _("%s: closing delimiter '%c' missing"), str, delim);
len = closing_delim - str - 1;
p = new_control_record ();
p->argnum = i;
if (xstrtoumax (argv[i], NULL, 10, &val, "") != LONGINT_OK)
- error (EXIT_FAILURE, 0, _("%s: invalid pattern"), quote (argv[i]));
+ die (EXIT_FAILURE, 0, _("%s: invalid pattern"), quote (argv[i]));
if (val == 0)
- error (EXIT_FAILURE, 0,
- _("%s: line number must be greater than zero"),
- argv[i]);
+ die (EXIT_FAILURE, 0,
+ _("%s: line number must be greater than zero"), argv[i]);
if (val < last_val)
{
char buf[INT_BUFSIZE_BOUND (uintmax_t)];
- error (EXIT_FAILURE, 0,
+ die (EXIT_FAILURE, 0,
_("line number %s is smaller than preceding line number, %s"),
- quote (argv[i]), umaxtostr (last_val, buf));
+ quote (argv[i]), umaxtostr (last_val, buf));
}
if (val == last_val)
default:
if (isprint (ch))
- error (EXIT_FAILURE, 0,
- _("invalid conversion specifier in suffix: %c"), ch);
+ die (EXIT_FAILURE, 0,
+ _("invalid conversion specifier in suffix: %c"), ch);
else
- error (EXIT_FAILURE, 0,
- _("invalid conversion specifier in suffix: \\%.3o"), ch);
+ die (EXIT_FAILURE, 0,
+ _("invalid conversion specifier in suffix: \\%.3o"), ch);
}
if (flags & ~ compatible_flags)
- error (EXIT_FAILURE, 0,
- _("invalid flags in conversion specification: %%%c%c"),
- (flags & ~ compatible_flags & FLAG_ALTERNATIVE ? '#' : '\''), ch);
+ die (EXIT_FAILURE, 0,
+ _("invalid flags in conversion specification: %%%c%c"),
+ (flags & ~ compatible_flags & FLAG_ALTERNATIVE ? '#' : '\''), ch);
}
/* Return the maximum number of bytes that can be generated by
if (*f == '%' && *++f != '%')
{
if (percent)
- error (EXIT_FAILURE, 0,
- _("too many %% conversion specifications in suffix"));
+ die (EXIT_FAILURE, 0,
+ _("too many %% conversion specifications in suffix"));
percent = true;
int flags;
f += get_format_flags (f, &flags);
}
if (! percent)
- error (EXIT_FAILURE, 0,
- _("missing %% conversion specification in suffix"));
+ die (EXIT_FAILURE, 0,
+ _("missing %% conversion specification in suffix"));
int maxlen = snprintf (NULL, 0, format, UINT_MAX);
if (! (0 <= maxlen && maxlen <= SIZE_MAX))
#include "system.h"
#include "argmatch.h"
+#include "die.h"
#include "error.h"
#include "parse-datetime.h"
#include "posixtm.h"
in_stream = fopen (input_filename, "r");
if (in_stream == NULL)
{
- error (EXIT_FAILURE, errno, "%s", quotef (input_filename));
+ die (EXIT_FAILURE, errno, "%s", quotef (input_filename));
}
}
}
if (fclose (in_stream) == EOF)
- error (EXIT_FAILURE, errno, "%s", quotef (input_filename));
+ die (EXIT_FAILURE, errno, "%s", quotef (input_filename));
free (line);
if (new_format)
{
if (format)
- error (EXIT_FAILURE, 0, _("multiple output formats specified"));
+ die (EXIT_FAILURE, 0, _("multiple output formats specified"));
format = new_format;
}
}
if (argv[optind][0] == '+')
{
if (format)
- error (EXIT_FAILURE, 0, _("multiple output formats specified"));
+ die (EXIT_FAILURE, 0, _("multiple output formats specified"));
format = argv[optind++] + 1;
}
else if (set_date || option_specified_date)
if (reference != NULL)
{
if (stat (reference, &refstats) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (reference));
+ die (EXIT_FAILURE, errno, "%s", quotef (reference));
when = get_stat_mtime (&refstats);
}
else
}
if (! valid_date)
- error (EXIT_FAILURE, 0, _("invalid date %s"), quote (datestr));
+ die (EXIT_FAILURE, 0, _("invalid date %s"), quote (datestr));
if (set_date)
{
#include "system.h"
#include "close-stream.h"
+#include "die.h"
#include "error.h"
#include "fd-reopen.h"
#include "gethrxtime.h"
{
uintmax_t ibs = input_blocksize;
char hbuf[LONGEST_HUMAN_READABLE + 1];
- error (EXIT_FAILURE, 0,
- _("memory exhausted by input buffer of size %"PRIuMAX
- " bytes (%s)"),
- ibs,
- human_readable (input_blocksize, hbuf,
- human_opts | human_base_1024, 1, 1));
+ die (EXIT_FAILURE, 0,
+ _("memory exhausted by input buffer of size %"PRIuMAX" bytes (%s)"),
+ ibs,
+ human_readable (input_blocksize, hbuf,
+ human_opts | human_base_1024, 1, 1));
}
real_buf += SWAB_ALIGN_OFFSET; /* allow space for swab */
{
uintmax_t obs = output_blocksize;
char hbuf[LONGEST_HUMAN_READABLE + 1];
- error (EXIT_FAILURE, 0,
- _("memory exhausted by output buffer of size %"PRIuMAX
- " bytes (%s)"),
- obs,
- human_readable (output_blocksize, hbuf,
- human_opts | human_base_1024, 1, 1));
+ die (EXIT_FAILURE, 0,
+ _("memory exhausted by output buffer of size %"PRIuMAX
+ " bytes (%s)"),
+ obs,
+ human_readable (output_blocksize, hbuf,
+ human_opts | human_base_1024, 1, 1));
}
obuf = ptr_align (real_obuf, page_size);
}
cleanup (void)
{
if (close (STDIN_FILENO) < 0)
- error (EXIT_FAILURE, errno,
- _("closing input file %s"), quoteaf (input_file));
+ die (EXIT_FAILURE, errno, _("closing input file %s"), quoteaf (input_file));
/* Don't remove this call to close, even though close_stdout
closes standard output. This close is necessary when cleanup
is called as part of a signal handler. */
if (close (STDOUT_FILENO) < 0)
- error (EXIT_FAILURE, errno,
- _("closing output file %s"), quoteaf (output_file));
+ die (EXIT_FAILURE, errno,
+ _("closing output file %s"), quoteaf (output_file));
}
/* Process any pending signals. If signals are caught, this function
invalid = LONGINT_OVERFLOW;
if (invalid != LONGINT_OK)
- error (EXIT_FAILURE, invalid == LONGINT_OVERFLOW ? EOVERFLOW : 0,
- "%s: %s", _("invalid number"), quote (val));
+ die (EXIT_FAILURE, invalid == LONGINT_OVERFLOW ? EOVERFLOW : 0,
+ "%s: %s", _("invalid number"), quote (val));
}
}
input_flags &= ~O_FULLBLOCK;
if (multiple_bits_set (conversions_mask & (C_ASCII | C_EBCDIC | C_IBM)))
- error (EXIT_FAILURE, 0, _("cannot combine any two of {ascii,ebcdic,ibm}"));
+ die (EXIT_FAILURE, 0, _("cannot combine any two of {ascii,ebcdic,ibm}"));
if (multiple_bits_set (conversions_mask & (C_BLOCK | C_UNBLOCK)))
- error (EXIT_FAILURE, 0, _("cannot combine block and unblock"));
+ die (EXIT_FAILURE, 0, _("cannot combine block and unblock"));
if (multiple_bits_set (conversions_mask & (C_LCASE | C_UCASE)))
- error (EXIT_FAILURE, 0, _("cannot combine lcase and ucase"));
+ die (EXIT_FAILURE, 0, _("cannot combine lcase and ucase"));
if (multiple_bits_set (conversions_mask & (C_EXCL | C_NOCREAT)))
- error (EXIT_FAILURE, 0, _("cannot combine excl and nocreat"));
+ die (EXIT_FAILURE, 0, _("cannot combine excl and nocreat"));
if (multiple_bits_set (input_flags & (O_DIRECT | O_NOCACHE))
|| multiple_bits_set (output_flags & (O_DIRECT | O_NOCACHE)))
- error (EXIT_FAILURE, 0, _("cannot combine direct and nocache"));
+ die (EXIT_FAILURE, 0, _("cannot combine direct and nocache"));
if (input_flags & O_NOCACHE)
{
{
struct stat st;
if (fstat (STDIN_FILENO, &st) != 0)
- error (EXIT_FAILURE, errno, _("cannot fstat %s"), quoteaf (file));
+ die (EXIT_FAILURE, errno, _("cannot fstat %s"), quoteaf (file));
if (usable_st_size (&st) && st.st_size < input_offset + offset)
{
/* When skipping past EOF, return the number of _full_ blocks
}
if (!ok)
- error (EXIT_FAILURE, errno, _("setting flags for %s"), quoteaf (name));
+ die (EXIT_FAILURE, errno, _("setting flags for %s"), quoteaf (name));
}
}
else
{
if (ifd_reopen (STDIN_FILENO, input_file, O_RDONLY | input_flags, 0) < 0)
- error (EXIT_FAILURE, errno, _("failed to open %s"),
- quoteaf (input_file));
+ die (EXIT_FAILURE, errno, _("failed to open %s"),
+ quoteaf (input_file));
}
offset = lseek (STDIN_FILENO, 0, SEEK_CUR);
|| ifd_reopen (STDOUT_FILENO, output_file, O_RDWR | opts, perms) < 0)
&& (ifd_reopen (STDOUT_FILENO, output_file, O_WRONLY | opts, perms)
< 0))
- error (EXIT_FAILURE, errno, _("failed to open %s"),
- quoteaf (output_file));
+ die (EXIT_FAILURE, errno, _("failed to open %s"),
+ quoteaf (output_file));
if (seek_records != 0 && !(conversions_mask & C_NOTRUNC))
{
unsigned long int obs = output_blocksize;
if (OFF_T_MAX / output_blocksize < seek_records)
- error (EXIT_FAILURE, 0,
- _("offset too large: "
- "cannot truncate to a length of seek=%"PRIuMAX""
- " (%lu-byte) blocks"),
- seek_records, obs);
+ die (EXIT_FAILURE, 0,
+ _("offset too large: "
+ "cannot truncate to a length of seek=%"PRIuMAX""
+ " (%lu-byte) blocks"),
+ seek_records, obs);
if (iftruncate (STDOUT_FILENO, size) != 0)
{
int ftruncate_errno = errno;
struct stat stdout_stat;
if (fstat (STDOUT_FILENO, &stdout_stat) != 0)
- error (EXIT_FAILURE, errno, _("cannot fstat %s"),
- quoteaf (output_file));
+ die (EXIT_FAILURE, errno, _("cannot fstat %s"),
+ quoteaf (output_file));
if (S_ISREG (stdout_stat.st_mode)
|| S_ISDIR (stdout_stat.st_mode)
|| S_TYPEISSHM (&stdout_stat))
- error (EXIT_FAILURE, ftruncate_errno,
- _("failed to truncate to %"PRIuMAX" bytes"
- " in output file %s"),
- size, quoteaf (output_file));
+ die (EXIT_FAILURE, ftruncate_errno,
+ _("failed to truncate to %"PRIuMAX" bytes"
+ " in output file %s"),
+ size, quoteaf (output_file));
}
}
}
#include "system.h"
#include "canonicalize.h"
+#include "die.h"
#include "error.h"
#include "fsusage.h"
#include "human.h"
/* Print the "no FS processed" diagnostic only if there was no preceding
diagnostic, e.g., if all have been excluded. */
if (exit_status == EXIT_SUCCESS)
- error (EXIT_FAILURE, 0, _("no file systems processed"));
+ die (EXIT_FAILURE, 0, _("no file systems processed"));
}
IF_LINT (free (columns));
#include "system.h"
#include "dircolors.h"
#include "c-strcase.h"
+#include "die.h"
#include "error.h"
#include "obstack.h"
#include "quote.h"
syntax = guess_shell_syntax ();
if (syntax == SHELL_SYNTAX_UNKNOWN)
{
- error (EXIT_FAILURE, 0,
+ die (EXIT_FAILURE, 0,
_("no SHELL environment variable, and no shell type option given"));
}
}
#include "argmatch.h"
#include "argv-iter.h"
#include "di-set.h"
+#include "die.h"
#include "error.h"
#include "exclude.h"
#include "fprintftime.h"
if (opt_threshold == 0 && *optarg == '-')
{
/* Do not allow -0, as this wouldn't make sense anyway. */
- error (EXIT_FAILURE, 0, _("invalid --threshold argument '-0'"));
+ die (EXIT_FAILURE, 0, _("invalid --threshold argument '-0'"));
}
}
break;
}
if (! (STREQ (files_from, "-") || freopen (files_from, "r", stdin)))
- error (EXIT_FAILURE, errno, _("cannot open %s for reading"),
- quoteaf (files_from));
+ die (EXIT_FAILURE, errno, _("cannot open %s for reading"),
+ quoteaf (files_from));
ai = argv_iter_init_stream (stdin);
di_set_free (di_mnt);
if (files_from && (ferror (stdin) || fclose (stdin) != 0) && ok)
- error (EXIT_FAILURE, 0, _("error reading %s"), quoteaf (files_from));
+ die (EXIT_FAILURE, 0, _("error reading %s"), quoteaf (files_from));
if (print_grand_total)
print_size (&tot_dui, _("total"));
#include <getopt.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "quote.h"
optind = 0; /* Force GNU getopt to re-initialize. */
while ((optc = getopt_long (argc, argv, "+iu:0", longopts, NULL)) != -1)
if (optc == 'u' && unsetenv (optarg))
- error (EXIT_CANCELED, errno, _("cannot unset %s"), quote (optarg));
+ die (EXIT_CANCELED, errno, _("cannot unset %s"), quote (optarg));
if (optind < argc && STREQ (argv[optind], "-"))
++optind;
if (putenv (argv[optind]))
{
*eq = '\0';
- error (EXIT_CANCELED, errno, _("cannot set %s"),
- quote (argv[optind]));
+ die (EXIT_CANCELED, errno, _("cannot set %s"),
+ quote (argv[optind]));
}
optind++;
}
#include <stdio.h>
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "quote.h"
if (max_column_width < column_width)
{
if (SIZE_MAX < column_width)
- error (EXIT_FAILURE, 0, _("tabs are too far apart"));
+ die (EXIT_FAILURE, 0, _("tabs are too far apart"));
max_column_width = column_width;
}
}
for (i = 0; i < entries; i++)
{
if (tabs[i] == 0)
- error (EXIT_FAILURE, 0, _("tab size cannot be 0"));
+ die (EXIT_FAILURE, 0, _("tab size cannot be 0"));
if (tabs[i] <= prev_tab)
- error (EXIT_FAILURE, 0, _("tab sizes must be ascending"));
+ die (EXIT_FAILURE, 0, _("tab sizes must be ascending"));
prev_tab = tabs[i];
}
}
cleanup_file_list_stdin (void)
{
if (have_read_stdin && fclose (stdin) != 0)
- error (EXIT_FAILURE, errno, "-");
+ die (EXIT_FAILURE, errno, "-");
}
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
-#include "error.h"
+#include "die.h"
#include "xstrndup.h"
#include "expand-common.h"
next_tab_column = column + 1;
if (next_tab_column < column)
- error (EXIT_FAILURE, 0, _("input line is too long"));
+ die (EXIT_FAILURE, 0, _("input line is too long"));
while (++column < next_tab_column)
if (putchar (' ') < 0)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
c = ' ';
}
{
column++;
if (!column)
- error (EXIT_FAILURE, 0, _("input line is too long"));
+ die (EXIT_FAILURE, 0, _("input line is too long"));
}
convert &= convert_entire_line || !! isblank (c);
return;
if (putchar (c) < 0)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
}
while (c != '\n');
}
#include "system.h"
#include <regex.h>
+#include "die.h"
#include "error.h"
#include "long-options.h"
#include "strnumcmp.h"
static void
syntax_error (void)
{
- error (EXPR_INVALID, 0, _("syntax error"));
+ die (EXPR_INVALID, 0, _("syntax error"));
}
#if ! HAVE_GMP
static void
integer_overflow (char op)
{
- error (EXPR_FAILURE, ERANGE, "%c", op);
+ die (EXPR_FAILURE, ERANGE, "%c", op);
abort (); /* notreached */
}
#endif
if (! looks_like_integer (s))
return false;
if (mpz_init_set_str (v->u.i, s, 10) != 0 && !HAVE_GMP)
- error (EXPR_FAILURE, ERANGE, "%s", (s));
+ die (EXPR_FAILURE, ERANGE, "%s", (s));
free (s);
v->type = integer;
return true;
RE_SYNTAX_POSIX_BASIC & ~RE_CONTEXT_INVALID_DUP & ~RE_NO_EMPTY_RANGES;
errmsg = re_compile_pattern (pv->u.s, strlen (pv->u.s), &re_buffer);
if (errmsg)
- error (EXPR_INVALID, 0, "%s", (errmsg));
+ die (EXPR_INVALID, 0, "%s", (errmsg));
re_buffer.newline_anchor = 0;
matchlen = re_match (&re_buffer, sv->u.s, strlen (sv->u.s), 0, &re_regs);
v = int_value (0);
}
else
- error (EXPR_FAILURE,
- (matchlen == -2 ? errno : EOVERFLOW),
- _("error in regular expression matcher"));
+ die (EXPR_FAILURE,
+ (matchlen == -2 ? errno : EOVERFLOW),
+ _("error in regular expression matcher"));
if (0 < re_regs.num_regs)
{
if (evaluate)
{
if (!toarith (l) || !toarith (r))
- error (EXPR_INVALID, 0, _("non-integer argument"));
+ die (EXPR_INVALID, 0, _("non-integer argument"));
if (fxn != multiply && mpz_sgn (r->u.i) == 0)
- error (EXPR_INVALID, 0, _("division by zero"));
+ die (EXPR_INVALID, 0, _("division by zero"));
((fxn == multiply ? mpz_mul
: fxn == divide ? mpz_tdiv_q
: mpz_tdiv_r)
if (evaluate)
{
if (!toarith (l) || !toarith (r))
- error (EXPR_INVALID, 0, _("non-integer argument"));
+ die (EXPR_INVALID, 0, _("non-integer argument"));
(fxn == plus ? mpz_add : mpz_sub) (l->u.i, l->u.i, r->u.i);
}
freev (r);
{
error (0, errno, _("string comparison failed"));
error (0, 0, _("set LC_ALL='C' to work around the problem"));
- error (EXPR_INVALID, 0,
- _("the strings compared were %s and %s"),
- quotearg_n_style (0, locale_quoting_style, l->u.s),
- quotearg_n_style (1, locale_quoting_style, r->u.s));
+ die (EXPR_INVALID, 0,
+ _("the strings compared were %s and %s"),
+ quotearg_n_style (0, locale_quoting_style, l->u.s),
+ quotearg_n_style (1, locale_quoting_style, r->u.s));
}
}
#include <assert.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "full-write.h"
#include "quote.h"
if (g <= L)
{
if (qpos >= QUEUE_SIZE)
- error (EXIT_FAILURE, 0, _("squfof queue overflow"));
+ die (EXIT_FAILURE, 0, _("squfof queue overflow"));
queue[qpos].Q = g;
queue[qpos].P = P % g;
qpos++;
{
size_t size = lbuf.end - lbuf.buf;
if (full_write (STDOUT_FILENO, lbuf.buf, size) != size)
- error (EXIT_FAILURE, errno, "%s", _("write error"));
+ die (EXIT_FAILURE, errno, "%s", _("write error"));
lbuf.end = lbuf.buf;
}
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "save-cwd.h"
#include "xgetcwd.h"
{
int save_errno = errno;
if (restore_cwd (&cwd) != 0)
- error (EXIT_FAILURE, errno,
- _("failed to return to initial working directory"));
+ die (EXIT_FAILURE, errno,
+ _("failed to return to initial working directory"));
free_cwd (&cwd);
errno = save_errno;
}
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "xdectoint.h"
}
if (have_read_stdin && fclose (stdin) == EOF)
- error (EXIT_FAILURE, errno, "-");
+ die (EXIT_FAILURE, errno, "-");
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
#include <getopt.h>
#include "system.h"
-#include "error.h"
+#include "die.h"
#include "group-list.h"
#include "quote.h"
errno = 0;
ruid = getuid ();
if (ruid == NO_UID && errno)
- error (EXIT_FAILURE, errno, _("cannot get real UID"));
+ die (EXIT_FAILURE, errno, _("cannot get real UID"));
errno = 0;
egid = getegid ();
if (egid == NO_GID && errno)
- error (EXIT_FAILURE, errno, _("cannot get effective GID"));
+ die (EXIT_FAILURE, errno, _("cannot get effective GID"));
errno = 0;
rgid = getgid ();
if (rgid == NO_GID && errno)
- error (EXIT_FAILURE, errno, _("cannot get real GID"));
+ die (EXIT_FAILURE, errno, _("cannot get real GID"));
if (!print_group_list (NULL, ruid, rgid, egid, true, ' '))
ok = false;
{
struct passwd *pwd = getpwnam (argv[optind]);
if (pwd == NULL)
- error (EXIT_FAILURE, 0, _("%s: no such user"),
- quote (argv[optind]));
+ die (EXIT_FAILURE, 0, _("%s: no such user"),
+ quote (argv[optind]));
ruid = pwd->pw_uid;
rgid = egid = pwd->pw_gid;
#include "system.h"
+#include "die.h"
#include "error.h"
#include "full-read.h"
#include "quote.h"
if (n_bytes > 0 && fwrite (buffer, 1, n_bytes, stdout) < n_bytes)
{
clearerr (stdout); /* To avoid redundant close_stdout diagnostic. */
- error (EXIT_FAILURE, errno, _("error writing %s"),
- quoteaf ("standard output"));
+ die (EXIT_FAILURE, errno, _("error writing %s"),
+ quoteaf ("standard output"));
}
}
if (SIZE_MAX < n_elide_0 + READ_BUFSIZE)
{
char umax_buf[INT_BUFSIZE_BOUND (n_elide_0)];
- error (EXIT_FAILURE, 0, _("%s: number of bytes is too large"),
- umaxtostr (n_elide_0, umax_buf));
+ die (EXIT_FAILURE, 0, _("%s: number of bytes is too large"),
+ umaxtostr (n_elide_0, umax_buf));
}
/* Two cases to consider...
if ( ! count_lines && elide_from_end && OFF_T_MAX < n_units)
{
char umax_buf[INT_BUFSIZE_BOUND (n_units)];
- error (EXIT_FAILURE, EOVERFLOW, "%s: %s", _("invalid number of bytes"),
- quote (umaxtostr (n_units, umax_buf)));
+ die (EXIT_FAILURE, EOVERFLOW, "%s: %s", _("invalid number of bytes"),
+ quote (umaxtostr (n_units, umax_buf)));
}
file_list = (optind < argc
ok &= head_file (file_list[i], n_units, count_lines, elide_from_end);
if (have_read_stdin && close (STDIN_FILENO) < 0)
- error (EXIT_FAILURE, errno, "-");
+ die (EXIT_FAILURE, errno, "-");
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
#include "system.h"
#include "long-options.h"
+#include "die.h"
#include "error.h"
#include "quote.h"
#include "xgethostname.h"
/* Set hostname to operand. */
char const *name = argv[optind];
if (sethostname (name, strlen (name)) != 0)
- error (EXIT_FAILURE, errno, _("cannot set name to %s"),
- quote (name));
+ die (EXIT_FAILURE, errno, _("cannot set name to %s"),
+ quote (name));
#else
- error (EXIT_FAILURE, 0,
- _("cannot set hostname; this system lacks the functionality"));
+ die (EXIT_FAILURE, 0,
+ _("cannot set hostname; this system lacks the functionality"));
#endif
}
{
hostname = xgethostname ();
if (hostname == NULL)
- error (EXIT_FAILURE, errno, _("cannot determine hostname"));
+ die (EXIT_FAILURE, errno, _("cannot determine hostname"));
printf ("%s\n", hostname);
}
#include <selinux/selinux.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "mgetgroups.h"
#include "quote.h"
/* politely decline if we're not on a SELinux/SMACK-enabled kernel. */
#ifdef HAVE_SMACK
if (!selinux_enabled && !smack_enabled)
- error (EXIT_FAILURE, 0,
- _("--context (-Z) works only on "
- "an SELinux/SMACK-enabled kernel"));
+ die (EXIT_FAILURE, 0,
+ _("--context (-Z) works only on "
+ "an SELinux/SMACK-enabled kernel"));
#else
if (!selinux_enabled)
- error (EXIT_FAILURE, 0,
- _("--context (-Z) works only on an SELinux-enabled kernel"));
+ die (EXIT_FAILURE, 0,
+ _("--context (-Z) works only on an SELinux-enabled kernel"));
#endif
just_context = true;
break;
}
if (n_ids && just_context)
- error (EXIT_FAILURE, 0,
- _("cannot print security context when user specified"));
+ die (EXIT_FAILURE, 0,
+ _("cannot print security context when user specified"));
if (just_user + just_group + just_group_list + just_context > 1)
- error (EXIT_FAILURE, 0, _("cannot print \"only\" of more than one choice"));
+ die (EXIT_FAILURE, 0, _("cannot print \"only\" of more than one choice"));
bool default_format = ! (just_user
|| just_group
|| just_context);
if (default_format && (use_real || use_name))
- error (EXIT_FAILURE, 0,
- _("cannot print only names or real IDs in default format"));
+ die (EXIT_FAILURE, 0,
+ _("cannot print only names or real IDs in default format"));
if (default_format && opt_zero)
- error (EXIT_FAILURE, 0,
- _("option --zero not permitted in default format"));
+ die (EXIT_FAILURE, 0,
+ _("option --zero not permitted in default format"));
/* If we are on a SELinux/SMACK-enabled kernel, no user is specified, and
either --context is specified or none of (-u,-g,-G) is specified,
|| (smack_enabled
&& smack_new_label_from_self (&context) < 0
&& just_context))
- error (EXIT_FAILURE, 0, _("can't get process context"));
+ die (EXIT_FAILURE, 0, _("can't get process context"));
}
if (n_ids == 1)
}
}
if (pwd == NULL)
- {
- error (0, 0, _("%s: no such user"), quote (spec));
- exit (EXIT_FAILURE);
- }
+ die (EXIT_FAILURE, 0, _("%s: no such user"), quote (spec));
pw_name = xstrdup (pwd->pw_name);
ruid = euid = pwd->pw_uid;
rgid = egid = pwd->pw_gid;
errno = 0;
euid = geteuid ();
if (euid == NO_UID && errno)
- error (EXIT_FAILURE, errno, _("cannot get effective UID"));
+ die (EXIT_FAILURE, errno, _("cannot get effective UID"));
}
if (just_user ? use_real
errno = 0;
ruid = getuid ();
if (ruid == NO_UID && errno)
- error (EXIT_FAILURE, errno, _("cannot get real UID"));
+ die (EXIT_FAILURE, errno, _("cannot get real UID"));
}
if (!just_user && (just_group || just_group_list || !just_context))
errno = 0;
egid = getegid ();
if (egid == NO_GID && errno)
- error (EXIT_FAILURE, errno, _("cannot get effective GID"));
+ die (EXIT_FAILURE, errno, _("cannot get effective GID"));
errno = 0;
rgid = getgid ();
if (rgid == NO_GID && errno)
- error (EXIT_FAILURE, errno, _("cannot get real GID"));
+ die (EXIT_FAILURE, errno, _("cannot get real GID"));
}
}
int err = (stat (file, &st) == 0 ? 0 : errno);
bool is_a_dir = !err && S_ISDIR (st.st_mode);
if (err && err != ENOENT)
- error (EXIT_FAILURE, err, _("failed to access %s"), quoteaf (file));
+ die (EXIT_FAILURE, err, _("failed to access %s"), quoteaf (file));
if (is_a_dir < looks_like_a_dir)
- error (EXIT_FAILURE, err, _("target %s is not a directory"),
- quoteaf (file));
+ die (EXIT_FAILURE, err, _("target %s is not a directory"),
+ quoteaf (file));
return is_a_dir;
}
unsigned long int tmp;
if (xstrtoul (owner_name, NULL, 0, &tmp, NULL) != LONGINT_OK
|| UID_T_MAX < tmp)
- error (EXIT_FAILURE, 0, _("invalid user %s"),
- quote (owner_name));
+ die (EXIT_FAILURE, 0, _("invalid user %s"),
+ quote (owner_name));
owner_id = tmp;
}
else
unsigned long int tmp;
if (xstrtoul (group_name, NULL, 0, &tmp, NULL) != LONGINT_OK
|| GID_T_MAX < tmp)
- error (EXIT_FAILURE, 0, _("invalid group %s"),
- quote (group_name));
+ die (EXIT_FAILURE, 0, _("invalid group %s"),
+ quote (group_name));
group_id = tmp;
}
else
if (! strip (to))
{
if (unlink (to) != 0) /* Cleanup. */
- error (EXIT_FAILURE, errno, _("cannot unlink %s"), quoteaf (to));
+ die (EXIT_FAILURE, errno, _("cannot unlink %s"), quoteaf (to));
return false;
}
if (x->preserve_timestamps && (strip_files || ! S_ISREG (from_sb.st_mode))
break;
case 't':
if (target_directory)
- error (EXIT_FAILURE, 0,
- _("multiple target directories specified"));
+ die (EXIT_FAILURE, 0,
+ _("multiple target directories specified"));
target_directory = optarg;
break;
case 'T':
/* Check for invalid combinations of arguments. */
if (dir_arg && strip_files)
- error (EXIT_FAILURE, 0,
- _("the strip option may not be used when installing a directory"));
+ die (EXIT_FAILURE, 0,
+ _("the strip option may not be used when installing a directory"));
if (dir_arg && target_directory)
- error (EXIT_FAILURE, 0,
- _("target directory not allowed when installing a directory"));
+ die (EXIT_FAILURE, 0,
+ _("target directory not allowed when installing a directory"));
if (target_directory)
{
struct stat st;
bool stat_success = stat (target_directory, &st) == 0 ? true : false;
if (! mkdir_and_install && ! stat_success)
- error (EXIT_FAILURE, errno, _("failed to access %s"),
- quoteaf (target_directory));
+ die (EXIT_FAILURE, errno, _("failed to access %s"),
+ quoteaf (target_directory));
if (stat_success && ! S_ISDIR (st.st_mode))
- error (EXIT_FAILURE, 0, _("target %s is not a directory"),
- quoteaf (target_directory));
+ die (EXIT_FAILURE, 0, _("target %s is not a directory"),
+ quoteaf (target_directory));
}
if (backup_suffix_string)
: no_backups);
if (x.preserve_security_context && (x.set_security_context || scontext))
- error (EXIT_FAILURE, 0,
- _("cannot set target context and preserve it"));
+ die (EXIT_FAILURE, 0,
+ _("cannot set target context and preserve it"));
if (scontext && setfscreatecon (se_const (scontext)) < 0)
- error (EXIT_FAILURE, errno,
- _("failed to set default file creation context to %s"),
- quote (scontext));
+ die (EXIT_FAILURE, errno,
+ _("failed to set default file creation context to %s"),
+ quote (scontext));
n_files = argc - optind;
file = argv + optind;
if (no_target_directory)
{
if (target_directory)
- error (EXIT_FAILURE, 0,
- _("cannot combine --target-directory (-t) "
- "and --no-target-directory (-T)"));
+ die (EXIT_FAILURE, 0,
+ _("cannot combine --target-directory (-t) "
+ "and --no-target-directory (-T)"));
if (2 < n_files)
{
error (0, 0, _("extra operand %s"), quoteaf (file[2]));
if (2 <= n_files && target_directory_operand (file[n_files - 1]))
target_directory = file[--n_files];
else if (2 < n_files)
- error (EXIT_FAILURE, 0, _("target %s is not a directory"),
- quoteaf (file[n_files - 1]));
+ die (EXIT_FAILURE, 0, _("target %s is not a directory"),
+ quoteaf (file[n_files - 1]));
}
if (specified_mode)
{
struct mode_change *change = mode_compile (specified_mode);
if (!change)
- error (EXIT_FAILURE, 0, _("invalid mode %s"), quote (specified_mode));
+ die (EXIT_FAILURE, 0, _("invalid mode %s"), quote (specified_mode));
mode = mode_adjust (0, false, 0, change, NULL);
dir_mode = mode_adjust (0, true, 0, change, &dir_mode_bits);
free (change);
#include <getopt.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "hard-locale.h"
if (! readlinebuffer_delim (&line->buf, fp, eolchar))
{
if (ferror (fp))
- error (EXIT_FAILURE, errno, _("read error"));
+ die (EXIT_FAILURE, errno, _("read error"));
freeline (line);
return false;
}
if (s_err == LONGINT_OVERFLOW || (s_err == LONGINT_OK && SIZE_MAX < val))
val = SIZE_MAX;
else if (s_err != LONGINT_OK || val == 0)
- error (EXIT_FAILURE, 0, _("invalid field number: %s"), quote (str));
+ die (EXIT_FAILURE, 0, _("invalid field number: %s"), quote (str));
result = val - 1;
if (s[1])
{
/* '0' must be all alone -- no '.FIELD'. */
- error (EXIT_FAILURE, 0, _("invalid field specifier: %s"), quote (s));
+ die (EXIT_FAILURE, 0, _("invalid field specifier: %s"), quote (s));
}
*file_index = 0;
*field_index = 0;
case '1':
case '2':
if (s[1] != '.')
- error (EXIT_FAILURE, 0, _("invalid field specifier: %s"), quote (s));
+ die (EXIT_FAILURE, 0, _("invalid field specifier: %s"), quote (s));
*file_index = s[0] - '0';
*field_index = string_to_join_field (s + 2);
break;
default:
- error (EXIT_FAILURE, 0,
- _("invalid file number in field spec: %s"), quote (s));
+ die (EXIT_FAILURE, 0,
+ _("invalid file number in field spec: %s"), quote (s));
/* Tell gcc -W -Wall that we can't get beyond this point.
This avoids a warning (otherwise legit) that the caller's copies
{
unsigned long int var1 = *var + 1;
unsigned long int val1 = val + 1;
- error (EXIT_FAILURE, 0, _("incompatible join fields %lu, %lu"),
- var1, val1);
+ die (EXIT_FAILURE, 0,
+ _("incompatible join fields %lu, %lu"), var1, val1);
}
*var = val;
}
unsigned long int val;
if (xstrtoul (optarg, NULL, 10, &val, "") != LONGINT_OK
|| (val != 1 && val != 2))
- error (EXIT_FAILURE, 0,
- _("invalid field number: %s"), quote (optarg));
+ die (EXIT_FAILURE, 0,
+ _("invalid field number: %s"), quote (optarg));
if (val == 1)
print_unpairables_1 = true;
else
case 'e':
if (empty_filler && ! STREQ (empty_filler, optarg))
- error (EXIT_FAILURE, 0,
- _("conflicting empty-field replacement strings"));
+ die (EXIT_FAILURE, 0,
+ _("conflicting empty-field replacement strings"));
empty_filler = optarg;
break;
if (STREQ (optarg, "\\0"))
newtab = '\0';
else
- error (EXIT_FAILURE, 0, _("multi-character tab %s"),
- quote (optarg));
+ die (EXIT_FAILURE, 0, _("multi-character tab %s"),
+ quote (optarg));
}
if (0 <= tab && tab != newtab)
- error (EXIT_FAILURE, 0, _("incompatible tabs"));
+ die (EXIT_FAILURE, 0, _("incompatible tabs"));
tab = newtab;
}
break;
fp1 = STREQ (g_names[0], "-") ? stdin : fopen (g_names[0], "r");
if (!fp1)
- error (EXIT_FAILURE, errno, "%s", quotef (g_names[0]));
+ die (EXIT_FAILURE, errno, "%s", quotef (g_names[0]));
fp2 = STREQ (g_names[1], "-") ? stdin : fopen (g_names[1], "r");
if (!fp2)
- error (EXIT_FAILURE, errno, "%s", quotef (g_names[1]));
+ die (EXIT_FAILURE, errno, "%s", quotef (g_names[1]));
if (fp1 == fp2)
- error (EXIT_FAILURE, errno, _("both files cannot be standard input"));
+ die (EXIT_FAILURE, errno, _("both files cannot be standard input"));
join (fp1, fp2);
if (fclose (fp1) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (g_names[0]));
+ die (EXIT_FAILURE, errno, "%s", quotef (g_names[0]));
if (fclose (fp2) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (g_names[1]));
+ die (EXIT_FAILURE, errno, "%s", quotef (g_names[1]));
if (issued_disorder_warning[0] || issued_disorder_warning[1])
return EXIT_FAILURE;
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "long-options.h"
#include "quote.h"
}
if (link (argv[optind], argv[optind + 1]) != 0)
- error (EXIT_FAILURE, errno, _("cannot create link %s to %s"),
- quoteaf_n (0, argv[optind + 1]), quoteaf_n (1, argv[optind]));
+ die (EXIT_FAILURE, errno, _("cannot create link %s to %s"),
+ quoteaf_n (0, argv[optind + 1]), quoteaf_n (1, argv[optind]));
return EXIT_SUCCESS;
}
#include "system.h"
#include "backupfile.h"
+#include "die.h"
#include "error.h"
#include "filenamecat.h"
#include "file-set.h"
int err = (stat_result == 0 ? 0 : errno);
bool is_a_dir = !err && S_ISDIR (st.st_mode);
if (err && ! errno_nonexisting (errno))
- error (EXIT_FAILURE, err, _("failed to access %s"), quoteaf (file));
+ die (EXIT_FAILURE, err, _("failed to access %s"), quoteaf (file));
if (is_a_dir < looks_like_a_dir)
- error (EXIT_FAILURE, err, _("target %s is not a directory"),
- quoteaf (file));
+ die (EXIT_FAILURE, err, _("target %s is not a directory"),
+ quoteaf (file));
return is_a_dir;
}
break;
case 't':
if (target_directory)
- error (EXIT_FAILURE, 0, _("multiple target directories specified"));
+ die (EXIT_FAILURE, 0, _("multiple target directories specified"));
else
{
struct stat st;
if (stat (optarg, &st) != 0)
- error (EXIT_FAILURE, errno, _("failed to access %s"),
- quoteaf (optarg));
+ die (EXIT_FAILURE, errno, _("failed to access %s"),
+ quoteaf (optarg));
if (! S_ISDIR (st.st_mode))
- error (EXIT_FAILURE, 0, _("target %s is not a directory"),
- quoteaf (optarg));
+ die (EXIT_FAILURE, 0, _("target %s is not a directory"),
+ quoteaf (optarg));
}
target_directory = optarg;
break;
if (no_target_directory)
{
if (target_directory)
- error (EXIT_FAILURE, 0,
- _("cannot combine --target-directory "
- "and --no-target-directory"));
+ die (EXIT_FAILURE, 0,
+ _("cannot combine --target-directory "
+ "and --no-target-directory"));
if (n_files != 2)
{
if (n_files < 2)
else if (2 <= n_files && target_directory_operand (file[n_files - 1]))
target_directory = file[--n_files];
else if (2 < n_files)
- error (EXIT_FAILURE, 0, _("target %s is not a directory"),
- quoteaf (file[n_files - 1]));
+ die (EXIT_FAILURE, 0, _("target %s is not a directory"),
+ quoteaf (file[n_files - 1]));
}
if (backup_suffix_string)
if (relative && !symbolic_link)
{
- error (EXIT_FAILURE, 0,
- _("cannot do --relative without --symbolic"));
+ die (EXIT_FAILURE, 0,
+ _("cannot do --relative without --symbolic"));
}
#include <getopt.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "long-options.h"
#include "quote.h"
using a fallback technique. */
cp = getlogin ();
if (! cp)
- error (EXIT_FAILURE, 0, _("no login name"));
+ die (EXIT_FAILURE, 0, _("no login name"));
puts (cp);
return EXIT_SUCCESS;
#include "acl.h"
#include "argmatch.h"
#include "dev-ino.h"
+#include "die.h"
#include "error.h"
#include "filenamecat.h"
#include "hard-locale.h"
case 'w':
if (! set_line_length (optarg))
- error (LS_FAILURE, 0, "%s: %s", _("invalid line width"),
- quote (optarg));
+ die (LS_FAILURE, 0, "%s: %s", _("invalid line width"),
+ quote (optarg));
break;
case 'x':
else
{
if (strchr (p1 + 1, '\n'))
- error (LS_FAILURE, 0, _("invalid time style format %s"),
- quote (p0));
+ die (LS_FAILURE, 0, _("invalid time style format %s"),
+ quote (p0));
*p1++ = '\0';
}
long_time_format[0] = p0;
#if HASH_ALGO_SHA512 || HASH_ALGO_SHA384
# include "sha512.h"
#endif
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "stdio--.h"
++line_number;
if (line_number == 0)
- error (EXIT_FAILURE, 0, _("%s: too many checksum lines"),
- quotef (checkfile_name));
+ die (EXIT_FAILURE, 0, _("%s: too many checksum lines"),
+ quotef (checkfile_name));
line_length = getline (&line, &line_chars_allocated, checkfile_stream);
if (line_length <= 0)
}
if (have_read_stdin && fclose (stdin) == EOF)
- error (EXIT_FAILURE, errno, _("standard input"));
+ die (EXIT_FAILURE, errno, _("standard input"));
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
#include <selinux/selinux.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "mkdir-p.h"
#include "modechange.h"
ret = setfscreatecon (se_const (scontext));
if (ret < 0)
- error (EXIT_FAILURE, errno,
- _("failed to set default file creation context to %s"),
- quote (scontext));
+ die (EXIT_FAILURE, errno,
+ _("failed to set default file creation context to %s"),
+ quote (scontext));
}
{
struct mode_change *change = mode_compile (specified_mode);
if (!change)
- error (EXIT_FAILURE, 0, _("invalid mode %s"),
- quote (specified_mode));
+ die (EXIT_FAILURE, 0, _("invalid mode %s"),
+ quote (specified_mode));
options.mode = mode_adjust (S_IRWXUGO, true, umask_value, change,
&options.mode_bits);
free (change);
#include <selinux/selinux.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "modechange.h"
#include "quote.h"
ret = setfscreatecon (se_const (scontext));
if (ret < 0)
- error (EXIT_FAILURE, errno,
- _("failed to set default file creation context to %s"),
- quote (scontext));
+ die (EXIT_FAILURE, errno,
+ _("failed to set default file creation context to %s"),
+ quote (scontext));
}
newmode = MODE_RW_UGO;
mode_t umask_value;
struct mode_change *change = mode_compile (specified_mode);
if (!change)
- error (EXIT_FAILURE, 0, _("invalid mode"));
+ die (EXIT_FAILURE, 0, _("invalid mode"));
umask_value = umask (0);
umask (umask_value);
newmode = mode_adjust (newmode, false, umask_value, change, NULL);
free (change);
if (newmode & ~S_IRWXUGO)
- error (EXIT_FAILURE, 0,
- _("mode must specify only file permission bits"));
+ die (EXIT_FAILURE, 0,
+ _("mode must specify only file permission bits"));
}
for (; optind < argc; ++optind)
#include <selinux/selinux.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "modechange.h"
#include "quote.h"
mode_t umask_value;
struct mode_change *change = mode_compile (specified_mode);
if (!change)
- error (EXIT_FAILURE, 0, _("invalid mode"));
+ die (EXIT_FAILURE, 0, _("invalid mode"));
umask_value = umask (0);
umask (umask_value);
newmode = mode_adjust (newmode, false, umask_value, change, NULL);
free (change);
if (newmode & ~S_IRWXUGO)
- error (EXIT_FAILURE, 0,
- _("mode must specify only file permission bits"));
+ die (EXIT_FAILURE, 0,
+ _("mode must specify only file permission bits"));
}
/* If the number of arguments is 0 or 1,
ret = setfscreatecon (se_const (scontext));
if (ret < 0)
- error (EXIT_FAILURE, errno,
- _("failed to set default file creation context to %s"),
- quote (scontext));
+ die (EXIT_FAILURE, errno,
+ _("failed to set default file creation context to %s"),
+ quote (scontext));
}
/* Only check the first character, to allow mnemonic usage like
{
case 'b': /* 'block' or 'buffered' */
#ifndef S_IFBLK
- error (EXIT_FAILURE, 0, _("block special files not supported"));
+ die (EXIT_FAILURE, 0, _("block special files not supported"));
#else
node_type = S_IFBLK;
#endif
case 'c': /* 'character' */
case 'u': /* 'unbuffered' */
#ifndef S_IFCHR
- error (EXIT_FAILURE, 0, _("character special files not supported"));
+ die (EXIT_FAILURE, 0, _("character special files not supported"));
#else
node_type = S_IFCHR;
#endif
if (xstrtoumax (s_major, NULL, 0, &i_major, NULL) != LONGINT_OK
|| i_major != (major_t) i_major)
- error (EXIT_FAILURE, 0,
- _("invalid major device number %s"), quote (s_major));
+ die (EXIT_FAILURE, 0,
+ _("invalid major device number %s"), quote (s_major));
if (xstrtoumax (s_minor, NULL, 0, &i_minor, NULL) != LONGINT_OK
|| i_minor != (minor_t) i_minor)
- error (EXIT_FAILURE, 0,
- _("invalid minor device number %s"), quote (s_minor));
+ die (EXIT_FAILURE, 0,
+ _("invalid minor device number %s"), quote (s_minor));
device = makedev (i_major, i_minor);
#ifdef NODEV
if (device == NODEV)
- error (EXIT_FAILURE, 0, _("invalid device %s %s"),
- s_major, s_minor);
+ die (EXIT_FAILURE, 0, _("invalid device %s %s"),
+ s_major, s_minor);
#endif
if (set_security_context)
defaultcon (argv[optind], node_type);
if (mknod (argv[optind], newmode | node_type, device) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (argv[optind]));
+ die (EXIT_FAILURE, errno, "%s", quotef (argv[optind]));
}
break;
if (set_security_context)
defaultcon (argv[optind], S_IFIFO);
if (mkfifo (argv[optind], newmode) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (argv[optind]));
+ die (EXIT_FAILURE, errno, "%s", quotef (argv[optind]));
break;
default:
}
if (specified_mode && lchmod (argv[optind], newmode) != 0)
- error (EXIT_FAILURE, errno, _("cannot set permissions of %s"),
- quoteaf (argv[optind]));
+ die (EXIT_FAILURE, errno, _("cannot set permissions of %s"),
+ quoteaf (argv[optind]));
return EXIT_SUCCESS;
}
#include "system.h"
#include "close-stream.h"
+#include "die.h"
#include "error.h"
#include "filenamecat.h"
#include "quote.h"
size_t len = strlen (template);
if (!len || template[len - 1] != 'X')
{
- error (EXIT_FAILURE, 0,
- _("with --suffix, template %s must end in X"),
- quote (template));
+ die (EXIT_FAILURE, 0,
+ _("with --suffix, template %s must end in X"),
+ quote (template));
}
suffix_len = strlen (suffix);
dest_name = xcharalloc (len + suffix_len + 1);
/* At this point, template is malloc'd, and suffix points into template. */
if (suffix_len && last_component (suffix) != suffix)
{
- error (EXIT_FAILURE, 0,
- _("invalid suffix %s, contains directory separator"),
- quote (suffix));
+ die (EXIT_FAILURE, 0,
+ _("invalid suffix %s, contains directory separator"),
+ quote (suffix));
}
x_count = count_consecutive_X_s (template, suffix - template);
if (x_count < 3)
- error (EXIT_FAILURE, 0, _("too few X's in template %s"), quote (template));
+ die (EXIT_FAILURE, 0, _("too few X's in template %s"), quote (template));
if (use_dest_dir)
{
dest_dir = "/tmp";
if (last_component (template) != template)
- error (EXIT_FAILURE, 0,
- _("invalid template, %s, contains directory separator"),
- quote (template));
+ die (EXIT_FAILURE, 0,
+ _("invalid template, %s, contains directory separator"),
+ quote (template));
}
else
{
dest_dir = (env && *env ? env : "/tmp");
}
if (IS_ABSOLUTE_FILE_NAME (template))
- error (EXIT_FAILURE, 0,
- _("invalid template, %s; with --tmpdir,"
- " it may not be absolute"),
- quote (template));
+ die (EXIT_FAILURE, 0,
+ _("invalid template, %s; with --tmpdir,"
+ " it may not be absolute"),
+ quote (template));
}
dest_name = file_name_concat (dest_dir, template, NULL);
#include "backupfile.h"
#include "copy.h"
#include "cp-hash.h"
+#include "die.h"
#include "error.h"
#include "filenamecat.h"
#include "remove.h"
static struct dev_ino dev_ino_buf;
x->root_dev_ino = get_root_dev_ino (&dev_ino_buf);
if (x->root_dev_ino == NULL)
- error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
- quoteaf ("/"));
+ die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
+ quoteaf ("/"));
}
}
int err = (stat (file, &st) == 0 ? 0 : errno);
bool is_a_dir = !err && S_ISDIR (st.st_mode);
if (err && err != ENOENT)
- error (EXIT_FAILURE, err, _("failed to access %s"), quoteaf (file));
+ die (EXIT_FAILURE, err, _("failed to access %s"), quoteaf (file));
return is_a_dir;
}
break;
case 't':
if (target_directory)
- error (EXIT_FAILURE, 0, _("multiple target directories specified"));
+ die (EXIT_FAILURE, 0, _("multiple target directories specified"));
else
{
struct stat st;
if (stat (optarg, &st) != 0)
- error (EXIT_FAILURE, errno, _("failed to access %s"),
- quoteaf (optarg));
+ die (EXIT_FAILURE, errno, _("failed to access %s"),
+ quoteaf (optarg));
if (! S_ISDIR (st.st_mode))
- error (EXIT_FAILURE, 0, _("target %s is not a directory"),
- quoteaf (optarg));
+ die (EXIT_FAILURE, 0, _("target %s is not a directory"),
+ quoteaf (optarg));
}
target_directory = optarg;
break;
if (no_target_directory)
{
if (target_directory)
- error (EXIT_FAILURE, 0,
- _("cannot combine --target-directory (-t) "
- "and --no-target-directory (-T)"));
+ die (EXIT_FAILURE, 0,
+ _("cannot combine --target-directory (-t) "
+ "and --no-target-directory (-T)"));
if (2 < n_files)
{
error (0, 0, _("extra operand %s"), quoteaf (file[2]));
if (target_directory_operand (file[n_files - 1]))
target_directory = file[--n_files];
else if (2 < n_files)
- error (EXIT_FAILURE, 0, _("target %s is not a directory"),
- quoteaf (file[n_files - 1]));
+ die (EXIT_FAILURE, 0, _("target %s is not a directory"),
+ quoteaf (file[n_files - 1]));
}
if (make_backups && x.interactive == I_ALWAYS_NO)
# include <sys/resource.h>
#endif
+#include "die.h"
#include "error.h"
#include "quote.h"
#include "xstrtol.h"
enum { MIN_ADJUSTMENT = 1 - 2 * NZERO, MAX_ADJUSTMENT = 2 * NZERO - 1 };
long int tmp;
if (LONGINT_OVERFLOW < xstrtol (adjustment_given, NULL, 10, &tmp, ""))
- error (EXIT_CANCELED, 0, _("invalid adjustment %s"),
- quote (adjustment_given));
+ die (EXIT_CANCELED, 0, _("invalid adjustment %s"),
+ quote (adjustment_given));
adjustment = MAX (MIN_ADJUSTMENT, MIN (tmp, MAX_ADJUSTMENT));
}
errno = 0;
current_niceness = GET_NICENESS ();
if (current_niceness == -1 && errno != 0)
- error (EXIT_CANCELED, errno, _("cannot get niceness"));
+ die (EXIT_CANCELED, errno, _("cannot get niceness"));
printf ("%d\n", current_niceness);
return EXIT_SUCCESS;
}
#else
current_niceness = GET_NICENESS ();
if (current_niceness == -1 && errno != 0)
- error (EXIT_CANCELED, errno, _("cannot get niceness"));
+ die (EXIT_CANCELED, errno, _("cannot get niceness"));
ok = (setpriority (PRIO_PROCESS, 0, current_niceness + adjustment) == 0);
#endif
if (!ok)
RE_SYNTAX_POSIX_BASIC & ~RE_CONTEXT_INVALID_DUP & ~RE_NO_EMPTY_RANGES;
errmsg = re_compile_pattern (optarg, strlen (optarg), regexp);
if (errmsg)
- error (EXIT_FAILURE, 0, "%s", (errmsg));
+ die (EXIT_FAILURE, 0, "%s", (errmsg));
break;
default:
rval = false;
next_line_no = line_no + page_incr;
if (next_line_no < line_no)
- error (EXIT_FAILURE, 0, _("line number overflow"));
+ die (EXIT_FAILURE, 0, _("line number overflow"));
line_no = next_line_no;
}
ok &= nl_file (argv[optind]);
if (have_read_stdin && fclose (stdin) == EOF)
- error (EXIT_FAILURE, errno, "-");
+ die (EXIT_FAILURE, errno, "-");
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
#include "mbsalign.h"
#include "argmatch.h"
#include "c-ctype.h"
+#include "die.h"
#include "error.h"
#include "quote.h"
#include "system.h"
num_size = snprintf (buf, buf_size, fmt, precision, val);
if (num_size < 0 || num_size >= (int) buf_size)
- error (EXIT_FAILURE, 0,
- _("failed to prepare value '%Lf' for printing"), val);
+ die (EXIT_FAILURE, 0,
+ _("failed to prepare value '%Lf' for printing"), val);
return;
}
num_size = snprintf (buf, buf_size - 1, fmt, prec, val,
suffix_power_char (power));
if (num_size < 0 || num_size >= (int) buf_size - 1)
- error (EXIT_FAILURE, 0,
- _("failed to prepare value '%Lf' for printing"), val);
+ die (EXIT_FAILURE, 0,
+ _("failed to prepare value '%Lf' for printing"), val);
if (scale == scale_IEC_I && power > 0)
strncat (buf, "i", buf_size - num_size - 1);
if (s_err != LONGINT_OK || *end || n == 0)
{
free (t_string);
- error (EXIT_FAILURE, 0, _("invalid unit size: %s"), quote (n_string));
+ die (EXIT_FAILURE, 0, _("invalid unit size: %s"), quote (n_string));
}
free (t_string);
for (i = 0; !(fmt[i] == '%' && fmt[i + 1] != '%'); i += (fmt[i] == '%') + 1)
{
if (!fmt[i])
- error (EXIT_FAILURE, 0,
- _("format %s has no %% directive"), quote (fmt));
+ die (EXIT_FAILURE, 0,
+ _("format %s has no %% directive"), quote (fmt));
prefix_len++;
}
errno = 0;
pad = strtol (fmt + i, &endptr, 10);
if (errno == ERANGE)
- error (EXIT_FAILURE, 0,
- _("invalid format %s (width overflow)"), quote (fmt));
+ die (EXIT_FAILURE, 0,
+ _("invalid format %s (width overflow)"), quote (fmt));
if (endptr != (fmt + i) && pad != 0)
{
i = endptr - fmt;
if (fmt[i] == '\0')
- error (EXIT_FAILURE, 0, _("format %s ends in %%"), quote (fmt));
+ die (EXIT_FAILURE, 0, _("format %s ends in %%"), quote (fmt));
if (fmt[i] == '.')
{
negative precision is only supported (and ignored)
when used with '.*f'. glibc at least will malform
output when passed a direct negative precision. */
- error (EXIT_FAILURE, 0,
- _("invalid precision in format %s"), quote (fmt));
+ die (EXIT_FAILURE, 0,
+ _("invalid precision in format %s"), quote (fmt));
}
i = endptr - fmt;
}
if (fmt[i] != 'f')
- error (EXIT_FAILURE, 0, _("invalid format %s,"
- " directive must be %%[0]['][-][N][.][N]f"),
- quote (fmt));
+ die (EXIT_FAILURE, 0, _("invalid format %s,"
+ " directive must be %%[0]['][-][N][.][N]f"),
+ quote (fmt));
i++;
suffix_pos = i;
for (; fmt[i] != '\0'; i += (fmt[i] == '%') + 1)
if (fmt[i] == '%' && fmt[i + 1] != '%')
- error (EXIT_FAILURE, 0, _("format %s has too many %% directives"),
- quote (fmt));
+ die (EXIT_FAILURE, 0, _("format %s has too many %% directives"),
+ quote (fmt));
if (prefix_len)
format_str_prefix = xstrndup (fmt, prefix_len);
case PADDING_OPTION:
if (xstrtol (optarg, NULL, 10, &padding_width, "") != LONGINT_OK
|| padding_width == 0)
- error (EXIT_FAILURE, 0, _("invalid padding value %s"),
- quote (optarg));
+ die (EXIT_FAILURE, 0, _("invalid padding value %s"),
+ quote (optarg));
if (padding_width < 0)
{
padding_alignment = MBS_ALIGN_LEFT;
case FIELD_OPTION:
if (n_frp)
- error (EXIT_FAILURE, 0, _("multiple field specifications"));
+ die (EXIT_FAILURE, 0, _("multiple field specifications"));
set_fields (optarg, SETFLD_ALLOW_DASH);
break;
case 'd':
/* Interpret -d '' to mean 'use the NUL byte as the delimiter.' */
if (optarg[0] != '\0' && optarg[1] != '\0')
- error (EXIT_FAILURE, 0,
- _("the delimiter must be a single character"));
+ die (EXIT_FAILURE, 0,
+ _("the delimiter must be a single character"));
delimiter = optarg[0];
break;
{
if (xstrtoumax (optarg, NULL, 10, &header, "") != LONGINT_OK
|| header == 0)
- error (EXIT_FAILURE, 0, _("invalid header value %s"),
- quote (optarg));
+ die (EXIT_FAILURE, 0, _("invalid header value %s"),
+ quote (optarg));
}
else
{
}
if (format_str != NULL && grouping)
- error (EXIT_FAILURE, 0, _("--grouping cannot be combined with --format"));
+ die (EXIT_FAILURE, 0, _("--grouping cannot be combined with --format"));
if (debug && ! locale_ok)
error (0, 0, _("failed to set locale"));
if (grouping)
{
if (scale_to != scale_none)
- error (EXIT_FAILURE, 0, _("grouping cannot be combined with --to"));
+ die (EXIT_FAILURE, 0, _("grouping cannot be combined with --to"));
if (debug && (strlen (nl_langinfo (THOUSEP)) == 0))
error (0, 0, _("grouping has no effect in this locale"));
}
#include <sys/types.h>
#include "system.h"
#include "argmatch.h"
+#include "die.h"
#include "error.h"
#include "ftoastr.h"
#include "quote.h"
}
if (n_skip != 0)
- error (EXIT_FAILURE, 0, _("cannot skip past end of combined input"));
+ die (EXIT_FAILURE, 0, _("cannot skip past end of combined input"));
return ok;
}
address_pad_len = 0;
break;
default:
- error (EXIT_FAILURE, 0,
- _("invalid output address radix '%c';\
+ die (EXIT_FAILURE, 0,
+ _("invalid output address radix '%c';\
it must be one character from [doxn]"),
- optarg[0]);
+ optarg[0]);
break;
}
break;
/* The minimum string length may be no larger than SIZE_MAX,
since we may allocate a buffer of this size. */
if (SIZE_MAX < tmp)
- error (EXIT_FAILURE, 0, _("%s is too large"), quote (optarg));
+ die (EXIT_FAILURE, 0, _("%s is too large"), quote (optarg));
string_min = tmp;
}
if (s_err != LONGINT_OK)
xstrtol_fatal (s_err, oi, c, long_options, optarg);
if (SIZE_MAX < w_tmp)
- error (EXIT_FAILURE, 0, _("%s is too large"), quote (optarg));
+ die (EXIT_FAILURE, 0, _("%s is too large"), quote (optarg));
desired_width = w_tmp;
}
break;
return EXIT_FAILURE;
if (flag_dump_strings && n_specs > 0)
- error (EXIT_FAILURE, 0,
- _("no type may be specified when dumping strings"));
+ die (EXIT_FAILURE, 0,
+ _("no type may be specified when dumping strings"));
n_files = argc - optind;
{
end_offset = n_bytes_to_skip + max_bytes_to_format;
if (end_offset < n_bytes_to_skip)
- error (EXIT_FAILURE, 0, _("skip-bytes + read-bytes is too large"));
+ die (EXIT_FAILURE, 0, _("skip-bytes + read-bytes is too large"));
}
if (n_specs == 0)
cleanup:
if (have_read_stdin && fclose (stdin) == EOF)
- error (EXIT_FAILURE, errno, _("standard input"));
+ die (EXIT_FAILURE, errno, _("standard input"));
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
static void
write_error (void)
{
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
abort ();
}
{
fileptr[files_open] = fopen (fnamptr[files_open], "r");
if (fileptr[files_open] == NULL)
- error (EXIT_FAILURE, errno, "%s", quotef (fnamptr[files_open]));
+ die (EXIT_FAILURE, errno, "%s", quotef (fnamptr[files_open]));
else if (fileno (fileptr[files_open]) == STDIN_FILENO)
opened_stdin = true;
fadvise (fileptr[files_open], FADVISE_SEQUENTIAL);
}
if (opened_stdin && have_read_stdin)
- error (EXIT_FAILURE, 0, _("standard input is closed"));
+ die (EXIT_FAILURE, 0, _("standard input is closed"));
/* Read a line from each file and output it to stdout separated by a
delimiter, until we go through the loop without successfully
{
/* Don't use the quote() quoting style, because that would double the
number of displayed backslashes, making the diagnostic look bogus. */
- error (EXIT_FAILURE, 0,
- _("delimiter list ends with an unescaped backslash: %s"),
- quotearg_n_style_colon (0, c_maybe_quoting_style, delim_arg));
+ die (EXIT_FAILURE, 0,
+ _("delimiter list ends with an unescaped backslash: %s"),
+ quotearg_n_style_colon (0, c_maybe_quoting_style, delim_arg));
}
bool ok = ((serial_merge ? paste_serial : paste_parallel)
free (delims);
if (have_read_stdin && fclose (stdin) == EOF)
- error (EXIT_FAILURE, errno, "-");
+ die (EXIT_FAILURE, errno, "-");
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
#include "system.h"
#include "canon-host.h"
+#include "die.h"
#include "error.h"
#include "hard-locale.h"
#include "readutmp.h"
STRUCT_UTMP *utmp_buf = NULL;
if (read_utmp (filename, &n_users, &utmp_buf, 0) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (filename));
+ die (EXIT_FAILURE, errno, "%s", quotef (filename));
scan_entries (n_users, utmp_buf, argc_names, argv_names);
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "hard-locale.h"
case PAGES_OPTION: /* --pages=FIRST_PAGE[:LAST_PAGE] */
{ /* dominates old opt +... */
if (! optarg)
- error (EXIT_FAILURE, 0,
- _("'--pages=FIRST_PAGE[:LAST_PAGE]' missing argument"));
+ die (EXIT_FAILURE, 0,
+ _("'--pages=FIRST_PAGE[:LAST_PAGE]' missing argument"));
else if (! first_last_page (oi, 0, optarg))
- error (EXIT_FAILURE, 0, _("invalid page range %s"),
- quote (optarg));
+ die (EXIT_FAILURE, 0, _("invalid page range %s"),
+ quote (optarg));
break;
}
first_page_number = 1;
if (parallel_files && explicit_columns)
- error (EXIT_FAILURE, 0,
+ die (EXIT_FAILURE, 0,
_("cannot specify number of columns when printing in parallel"));
if (parallel_files && print_across_flag)
- error (EXIT_FAILURE, 0,
+ die (EXIT_FAILURE, 0,
_("cannot specify both printing across and printing in parallel"));
/* Translate some old short options to new/long options.
IF_LINT (free (file_names));
if (have_read_stdin && fclose (stdin) == EOF)
- error (EXIT_FAILURE, errno, _("standard input"));
+ die (EXIT_FAILURE, errno, _("standard input"));
return failed_opens ? EXIT_FAILURE : EXIT_SUCCESS;
}
- (columns - 1) * col_sep_length) / columns;
if (chars_per_column < 1)
- error (EXIT_FAILURE, 0, _("page width too narrow"));
+ die (EXIT_FAILURE, 0, _("page width too narrow"));
if (numbered_lines)
{
if (p->status == CLOSED)
return;
if (ferror (p->fp))
- error (EXIT_FAILURE, errno, "%s", quotef (p->name));
+ die (EXIT_FAILURE, errno, "%s", quotef (p->name));
if (fileno (p->fp) != STDIN_FILENO && fclose (p->fp) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (p->name));
+ die (EXIT_FAILURE, errno, "%s", quotef (p->name));
if (!parallel_files)
{
print_white_space ();
if (page_number == 0)
- error (EXIT_FAILURE, 0, _("page number overflow"));
+ die (EXIT_FAILURE, 0, _("page number overflow"));
/* The translator must ensure that formatting the translation of
"Page %"PRIuMAX does not generate more than (sizeof page_text - 1)
#include "system.h"
#include "c-strtod.h"
+#include "die.h"
#include "error.h"
#include "quote.h"
#include "unicodeio.h"
++esc_length, ++p)
esc_value = esc_value * 16 + hextobin (*p);
if (esc_length == 0)
- error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
+ die (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
putchar (esc_value);
}
else if (isodigit (*p))
--esc_length, ++p)
{
if (! isxdigit (to_uchar (*p)))
- error (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
+ die (EXIT_FAILURE, 0, _("missing hexadecimal number in escape"));
uni_value = uni_value * 16 + hextobin (*p);
}
if ((uni_value <= 0x9f
&& uni_value != 0x24 && uni_value != 0x40 && uni_value != 0x60)
|| (uni_value >= 0xd800 && uni_value <= 0xdfff))
- error (EXIT_FAILURE, 0, _("invalid universal character name \\%c%0*x"),
- esc_char, (esc_char == 'u' ? 4 : 8), uni_value);
+ die (EXIT_FAILURE, 0, _("invalid universal character name \\%c%0*x"),
+ esc_char, (esc_char == 'u' ? 4 : 8), uni_value);
print_unicode_char (stdout, uni_value, 0);
}
if (INT_MIN <= width && width <= INT_MAX)
field_width = width;
else
- error (EXIT_FAILURE, 0, _("invalid field width: %s"),
- quote (*argv));
+ die (EXIT_FAILURE, 0, _("invalid field width: %s"),
+ quote (*argv));
++argv;
--argc;
}
precision = -1;
}
else if (INT_MAX < prec)
- error (EXIT_FAILURE, 0, _("invalid precision: %s"),
- quote (*argv));
+ die (EXIT_FAILURE, 0, _("invalid precision: %s"),
+ quote (*argv));
else
precision = prec;
++argv;
{
unsigned char conversion = *f;
if (! ok[conversion])
- error (EXIT_FAILURE, 0,
- _("%.*s: invalid conversion specification"),
- (int) (f + 1 - direc_start), direc_start);
+ die (EXIT_FAILURE, 0,
+ _("%.*s: invalid conversion specification"),
+ (int) (f + 1 - direc_start), direc_start);
}
print_direc (direc_start, direc_length, *f,
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include <regex.h>
#include "argmatch.h"
#include "diacrit.h"
static void ATTRIBUTE_NORETURN
matcher_error (void)
{
- error (0, errno, _("error in regular expression matcher"));
- exit (EXIT_FAILURE);
+ die (EXIT_FAILURE, errno, _("error in regular expression matcher"));
}
/*------------------------------------------------------.
message = re_compile_pattern (string, strlen (string), pattern);
if (message)
- error (EXIT_FAILURE, 0, _("%s (for regexp %s)"), message, quote (string));
+ die (EXIT_FAILURE, 0, _("%s (for regexp %s)"), message, quote (string));
/* The fastmap should be compiled before 're_match'. The following
call is not mandatory, because 're_search' is always called sooner,
block->start = read_file (file_name, &used_length);
if (!block->start)
- error (EXIT_FAILURE, errno, "%s", quotef (using_stdin ? "-" : file_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (using_stdin ? "-" : file_name));
block->end = block->start + used_length;
}
unsigned long int tmp_ulong;
if (xstrtoul (optarg, NULL, 0, &tmp_ulong, NULL) != LONGINT_OK
|| ! (0 < tmp_ulong && tmp_ulong <= INT_MAX))
- error (EXIT_FAILURE, 0, _("invalid gap width: %s"),
- quote (optarg));
+ die (EXIT_FAILURE, 0, _("invalid gap width: %s"),
+ quote (optarg));
gap_size = tmp_ulong;
break;
}
unsigned long int tmp_ulong;
if (xstrtoul (optarg, NULL, 0, &tmp_ulong, NULL) != LONGINT_OK
|| ! (0 < tmp_ulong && tmp_ulong <= INT_MAX))
- error (EXIT_FAILURE, 0, _("invalid line width: %s"),
- quote (optarg));
+ die (EXIT_FAILURE, 0, _("invalid line width: %s"),
+ quote (optarg));
line_width = tmp_ulong;
break;
}
if (optind < argc)
{
if (! freopen (argv[optind], "w", stdout))
- error (EXIT_FAILURE, errno, "%s", quotef (argv[optind]));
+ die (EXIT_FAILURE, errno, "%s", quotef (argv[optind]));
optind++;
}
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "quote.h"
#include "root-dev-ino.h"
dirp = opendir ("..");
if (dirp == NULL)
- error (EXIT_FAILURE, errno, _("cannot open directory %s"),
- quote (nth_parent (parent_height)));
+ die (EXIT_FAILURE, errno, _("cannot open directory %s"),
+ quote (nth_parent (parent_height)));
fd = dirfd (dirp);
if ((0 <= fd ? fchdir (fd) : chdir ("..")) < 0)
- error (EXIT_FAILURE, errno, _("failed to chdir to %s"),
- quote (nth_parent (parent_height)));
+ die (EXIT_FAILURE, errno, _("failed to chdir to %s"),
+ quote (nth_parent (parent_height)));
if ((0 <= fd ? fstat (fd, &parent_sb) : stat (".", &parent_sb)) < 0)
- error (EXIT_FAILURE, errno, _("failed to stat %s"),
- quote (nth_parent (parent_height)));
+ die (EXIT_FAILURE, errno, _("failed to stat %s"),
+ quote (nth_parent (parent_height)));
/* If parent and child directory are on different devices, then we
can't rely on d_ino for useful i-node numbers; use lstat instead. */
{
/* Note that this diagnostic serves for both readdir
and closedir failures. */
- error (EXIT_FAILURE, errno, _("reading directory %s"),
- quote (nth_parent (parent_height)));
+ die (EXIT_FAILURE, errno, _("reading directory %s"),
+ quote (nth_parent (parent_height)));
}
if ( ! found)
- error (EXIT_FAILURE, 0,
- _("couldn't find directory entry in %s with matching i-node"),
- quote (nth_parent (parent_height)));
+ die (EXIT_FAILURE, 0,
+ _("couldn't find directory entry in %s with matching i-node"),
+ quote (nth_parent (parent_height)));
*dot_sb = parent_sb;
}
struct stat dot_sb;
if (root_dev_ino == NULL)
- error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
- quoteaf ("/"));
+ die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
+ quoteaf ("/"));
if (stat (".", &dot_sb) < 0)
- error (EXIT_FAILURE, errno, _("failed to stat %s"), quoteaf ("."));
+ die (EXIT_FAILURE, errno, _("failed to stat %s"), quoteaf ("."));
while (1)
{
#include "system.h"
#include "canonicalize.h"
+#include "die.h"
#include "error.h"
#include "relpath.h"
{
struct stat sb;
if (stat (path, &sb) != 0)
- error (EXIT_FAILURE, errno, _("cannot stat %s"), quoteaf (path));
+ die (EXIT_FAILURE, errno, _("cannot stat %s"), quoteaf (path));
return S_ISDIR (sb.st_mode);
}
{
can_relative_to = realpath_canon (relative_to, can_mode);
if (!can_relative_to)
- error (EXIT_FAILURE, errno, "%s", quotef (relative_to));
+ die (EXIT_FAILURE, errno, "%s", quotef (relative_to));
if (need_dir && !isdir (can_relative_to))
- error (EXIT_FAILURE, ENOTDIR, "%s", quotef (relative_to));
+ die (EXIT_FAILURE, ENOTDIR, "%s", quotef (relative_to));
}
if (relative_base == relative_to)
can_relative_base = can_relative_to;
{
char *base = realpath_canon (relative_base, can_mode);
if (!base)
- error (EXIT_FAILURE, errno, "%s", quotef (relative_base));
+ die (EXIT_FAILURE, errno, "%s", quotef (relative_base));
if (need_dir && !isdir (base))
- error (EXIT_FAILURE, ENOTDIR, "%s", quotef (relative_base));
+ die (EXIT_FAILURE, ENOTDIR, "%s", quotef (relative_base));
/* --relative-to is a no-op if it does not have --relative-base
as a prefix */
if (path_prefix (base, can_relative_to))
#include "system.h"
#include "argmatch.h"
+#include "die.h"
#include "error.h"
#include "remove.h"
#include "root-dev-ino.h"
case NO_PRESERVE_ROOT:
if (! STREQ (argv[optind - 1], "--no-preserve-root"))
- error (EXIT_FAILURE, 0,
- _("you may not abbreviate the --no-preserve-root option"));
+ die (EXIT_FAILURE, 0,
+ _("you may not abbreviate the --no-preserve-root option"));
preserve_root = false;
break;
static struct dev_ino dev_ino_buf;
x.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
if (x.root_dev_ino == NULL)
- error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
- quoteaf ("/"));
+ die (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
+ quoteaf ("/"));
}
uintmax_t n_files = argc - optind;
#include <selinux/context.h>
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "quote.h"
{
case 'r':
if (role)
- error (EXIT_FAILURE, 0, _("multiple roles"));
+ die (EXIT_FAILURE, 0, _("multiple roles"));
role = optarg;
break;
case 't':
if (type)
- error (EXIT_FAILURE, 0, _("multiple types"));
+ die (EXIT_FAILURE, 0, _("multiple types"));
type = optarg;
break;
case 'u':
if (user)
- error (EXIT_FAILURE, 0, _("multiple users"));
+ die (EXIT_FAILURE, 0, _("multiple users"));
user = optarg;
break;
case 'l':
if (range)
- error (EXIT_FAILURE, 0, _("multiple levelranges"));
+ die (EXIT_FAILURE, 0, _("multiple levelranges"));
range = optarg;
break;
case 'c':
if (argc - optind == 0)
{
if (getcon (&cur_context) < 0)
- error (EXIT_FAILURE, errno, _("failed to get current context"));
+ die (EXIT_FAILURE, errno, _("failed to get current context"));
fputs (cur_context, stdout);
fputc ('\n', stdout);
return EXIT_SUCCESS;
}
if (is_selinux_enabled () != 1)
- error (EXIT_FAILURE, 0, _("%s may be used only on a SELinux kernel"),
- program_name);
+ die (EXIT_FAILURE, 0, _("%s may be used only on a SELinux kernel"),
+ program_name);
if (context)
{
con = context_new (context);
if (!con)
- error (EXIT_FAILURE, errno, _("failed to create security context: %s"),
- quote (context));
+ die (EXIT_FAILURE, errno, _("failed to create security context: %s"),
+ quote (context));
}
else
{
if (getcon (&cur_context) < 0)
- error (EXIT_FAILURE, errno, _("failed to get current context"));
+ die (EXIT_FAILURE, errno, _("failed to get current context"));
/* We will generate context based on process transition */
if (compute_trans)
{
/* Get context of file to be executed */
if (getfilecon (argv[optind], &file_context) == -1)
- error (EXIT_FAILURE, errno,
- _("failed to get security context of %s"),
- quoteaf (argv[optind]));
+ die (EXIT_FAILURE, errno,
+ _("failed to get security context of %s"),
+ quoteaf (argv[optind]));
/* compute result of process transition */
if (security_compute_create (cur_context, file_context,
string_to_security_class ("process"),
&new_context) != 0)
- error (EXIT_FAILURE, errno, _("failed to compute a new context"));
+ die (EXIT_FAILURE, errno, _("failed to compute a new context"));
/* free contexts */
freecon (file_context);
freecon (cur_context);
con = context_new (cur_context);
if (!con)
- error (EXIT_FAILURE, errno, _("failed to create security context: %s"),
- quote (cur_context));
+ die (EXIT_FAILURE, errno, _("failed to create security context: %s"),
+ quote (cur_context));
if (user && context_user_set (con, user))
- error (EXIT_FAILURE, errno, _("failed to set new user: %s"),
- quote (user));
+ die (EXIT_FAILURE, errno, _("failed to set new user: %s"),
+ quote (user));
if (type && context_type_set (con, type))
- error (EXIT_FAILURE, errno, _("failed to set new type: %s"),
- quote (type));
+ die (EXIT_FAILURE, errno, _("failed to set new type: %s"),
+ quote (type));
if (range && context_range_set (con, range))
- error (EXIT_FAILURE, errno, _("failed to set new range: %s"),
- quote (range));
+ die (EXIT_FAILURE, errno, _("failed to set new range: %s"),
+ quote (range));
if (role && context_role_set (con, role))
- error (EXIT_FAILURE, errno, _("failed to set new role: %s"),
- quote (role));
+ die (EXIT_FAILURE, errno, _("failed to set new role: %s"),
+ quote (role));
}
if (security_check_context (context_str (con)) < 0)
- error (EXIT_FAILURE, errno, _("invalid context: %s"),
- quote (context_str (con)));
+ die (EXIT_FAILURE, errno, _("invalid context: %s"),
+ quote (context_str (con)));
if (setexeccon (context_str (con)) != 0)
- error (EXIT_FAILURE, errno, _("unable to set security context %s"),
- quote (context_str (con)));
+ die (EXIT_FAILURE, errno, _("unable to set security context %s"),
+ quote (context_str (con)));
if (cur_context != NULL)
freecon (cur_context);
#include <selinux/context.h>
#include <sys/types.h>
+#include "die.h"
#include "error.h"
#include "system.h"
#include "canonicalize.h"
with libselinux < 2.1.5 2011-0826. */
newpath = canonicalize_filename_mode (path, CAN_MISSING);
if (! newpath)
- error (EXIT_FAILURE, errno, _("error canonicalizing %s"),
- quoteaf (path));
+ die (EXIT_FAILURE, errno, _("error canonicalizing %s"),
+ quoteaf (path));
path = newpath;
}
fts entries, which may be quicker to process in any case. */
newpath = canonicalize_filename_mode (path, CAN_MISSING);
if (! newpath)
- error (EXIT_FAILURE, errno, _("error canonicalizing %s"),
- quoteaf (path));
+ die (EXIT_FAILURE, errno, _("error canonicalizing %s"),
+ quoteaf (path));
}
const char *ftspath[2] = { newpath ? newpath : path, NULL };
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "c-strtod.h"
#include "error.h"
#include "quote.h"
for (i = 0; ! (fmt[i] == '%' && fmt[i + 1] != '%'); i += (fmt[i] == '%') + 1)
{
if (!fmt[i])
- error (EXIT_FAILURE, 0,
- _("format %s has no %% directive"), quote (fmt));
+ die (EXIT_FAILURE, 0,
+ _("format %s has no %% directive"), quote (fmt));
prefix_len++;
}
has_L = (fmt[i] == 'L');
i += has_L;
if (fmt[i] == '\0')
- error (EXIT_FAILURE, 0, _("format %s ends in %%"), quote (fmt));
+ die (EXIT_FAILURE, 0, _("format %s ends in %%"), quote (fmt));
if (! strchr ("efgaEFGA", fmt[i]))
- error (EXIT_FAILURE, 0,
- _("format %s has unknown %%%c directive"), quote (fmt), fmt[i]);
+ die (EXIT_FAILURE, 0,
+ _("format %s has unknown %%%c directive"), quote (fmt), fmt[i]);
for (i++; ; i += (fmt[i] == '%') + 1)
if (fmt[i] == '%' && fmt[i + 1] != '%')
- error (EXIT_FAILURE, 0, _("format %s has too many %% directives"),
- quote (fmt));
+ die (EXIT_FAILURE, 0, _("format %s has too many %% directives"),
+ quote (fmt));
else if (fmt[i])
suffix_len++;
else
io_error (void)
{
/* FIXME: consider option to silently ignore errno=EPIPE */
- error (0, errno, _("standard output"));
clearerr (stdout);
- exit (EXIT_FAILURE);
+ die (EXIT_FAILURE, errno, _("standard output"));
}
/* Actually print the sequence of numbers in the specified range, with the
#include "system.h"
#include "argmatch.h"
#include "xdectoint.h"
+#include "die.h"
#include "error.h"
#include "fcntl--.h"
#include "human.h"
case RANDOM_SOURCE_OPTION:
if (random_source && !STREQ (random_source, optarg))
- error (EXIT_FAILURE, 0, _("multiple random sources specified"));
+ die (EXIT_FAILURE, 0, _("multiple random sources specified"));
random_source = optarg;
break;
randint_source = randint_all_new (random_source, SIZE_MAX);
if (! randint_source)
- error (EXIT_FAILURE, errno, "%s", quotef (random_source));
+ die (EXIT_FAILURE, errno, "%s", quotef (random_source));
atexit (clear_random_data);
for (i = 0; i < n_files; i++)
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "getopt.h"
while (readlinebuffer_delim (line, in, eolbyte) != NULL && n_lines++);
if (! n_lines)
- error (EXIT_FAILURE, EOVERFLOW, _("too many input lines"));
+ die (EXIT_FAILURE, EOVERFLOW, _("too many input lines"));
freebuffer (&dummy);
}
/* no more input lines, or an input error. */
if (ferror (in))
- error (EXIT_FAILURE, errno, _("read error"));
+ die (EXIT_FAILURE, errno, _("read error"));
*out_rsrv = rsrv;
return MIN (k, n_lines);
avoiding the reservoir CPU overhead when reading < RESERVOIR_MIN_INPUT
from a pipe, and allow us to dispense with the input_size() function. */
if (!(buf = fread_file (in, &used)))
- error (EXIT_FAILURE, errno, _("read error"));
+ die (EXIT_FAILURE, errno, _("read error"));
if (used && buf[used - 1] != eolbyte)
buf[used++] = eolbyte;
bool invalid = !p;
if (input_range)
- error (EXIT_FAILURE, 0, _("multiple -i options specified"));
+ die (EXIT_FAILURE, 0, _("multiple -i options specified"));
input_range = true;
if (p)
n_lines = hi_input - lo_input + 1;
invalid |= ((lo_input <= hi_input) == (n_lines == 0));
if (invalid)
- error (EXIT_FAILURE, errno, "%s: %s", _("invalid input range"),
- quote (optarg));
+ die (EXIT_FAILURE, errno, "%s: %s", _("invalid input range"),
+ quote (optarg));
}
break;
if (e == LONGINT_OK)
head_lines = MIN (head_lines, argval);
else if (e != LONGINT_OVERFLOW)
- error (EXIT_FAILURE, 0, _("invalid line count: %s"),
- quote (optarg));
+ die (EXIT_FAILURE, 0, _("invalid line count: %s"),
+ quote (optarg));
}
break;
case 'o':
if (outfile && !STREQ (outfile, optarg))
- error (EXIT_FAILURE, 0, _("multiple output files specified"));
+ die (EXIT_FAILURE, 0, _("multiple output files specified"));
outfile = optarg;
break;
case RANDOM_SOURCE_OPTION:
if (random_source && !STREQ (random_source, optarg))
- error (EXIT_FAILURE, 0, _("multiple random sources specified"));
+ die (EXIT_FAILURE, 0, _("multiple random sources specified"));
random_source = optarg;
break;
if (n_operands == 1)
if (! (STREQ (operand[0], "-") || ! head_lines
|| freopen (operand[0], "r", stdin)))
- error (EXIT_FAILURE, errno, "%s", quotef (operand[0]));
+ die (EXIT_FAILURE, errno, "%s", quotef (operand[0]));
fadvise (stdin, FADVISE_SEQUENTIAL);
? SIZE_MAX
: randperm_bound (head_lines, n_lines)));
if (! randint_source)
- error (EXIT_FAILURE, errno, "%s", quotef (random_source));
+ die (EXIT_FAILURE, errno, "%s", quotef (random_source));
if (use_reservoir_sampling)
{
stdin. */
if (! (echo || input_range)
&& (fclose (stdin) != 0))
- error (EXIT_FAILURE, errno, _("read error"));
+ die (EXIT_FAILURE, errno, _("read error"));
if (!repeat)
permutation = randperm_new (randint_source, head_lines, n_lines);
if (outfile && ! freopen (outfile, "w", stdout))
- error (EXIT_FAILURE, errno, "%s", quotef (outfile));
+ die (EXIT_FAILURE, errno, "%s", quotef (outfile));
/* Generate output according to requested method */
if (repeat)
else
{
if (n_lines == 0)
- error (EXIT_FAILURE, 0, _("no lines to repeat"));
+ die (EXIT_FAILURE, 0, _("no lines to repeat"));
if (input_range)
i = write_random_numbers (randint_source, head_lines,
lo_input, hi_input, eolbyte);
}
if (i != 0)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
#ifdef lint
free (permutation);
#include "system.h"
#include "c-strtod.h"
+#include "die.h"
#include "error.h"
#include "long-options.h"
#include "quote.h"
usage (EXIT_FAILURE);
if (xnanosleep (seconds))
- error (EXIT_FAILURE, errno, _("cannot read realtime clock"));
+ die (EXIT_FAILURE, errno, _("cannot read realtime clock"));
return EXIT_SUCCESS;
}
#include <assert.h>
#include "system.h"
#include "argmatch.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "filevercmp.h"
/* Report MESSAGE for FILE, then clean up and exit.
If FILE is null, it represents standard output. */
-static void die (char const *, char const *) ATTRIBUTE_NORETURN;
+static void sort_die (char const *, char const *) ATTRIBUTE_NORETURN;
static void
-die (char const *message, char const *file)
+sort_die (char const *message, char const *file)
{
- error (0, errno, "%s: %s", message,
- quotef (file ? file : _("standard output")));
- exit (SORT_FAILURE);
+ die (SORT_FAILURE, errno, "%s: %s", message,
+ quotef (file ? file : _("standard output")));
}
void
pid_t cpid = waitpid ((pid ? pid : -1), &status, (pid ? 0 : WNOHANG));
if (cpid < 0)
- error (SORT_FAILURE, errno, _("waiting for %s [-d]"),
- quoteaf (compress_program));
+ die (SORT_FAILURE, errno, _("waiting for %s [-d]"),
+ quoteaf (compress_program));
else if (0 < cpid && (0 < pid || delete_proc (cpid)))
{
if (! WIFEXITED (status) || WEXITSTATUS (status))
- error (SORT_FAILURE, 0, _("%s [-d] terminated abnormally"),
- quoteaf (compress_program));
+ die (SORT_FAILURE, 0, _("%s [-d] terminated abnormally"),
+ quoteaf (compress_program));
--nprocs;
}
if (fd < 0)
{
if (! (survive_fd_exhaustion && errno == EMFILE))
- error (SORT_FAILURE, errno, _("cannot create temporary file in %s"),
- quoteaf (temp_dir));
+ die (SORT_FAILURE, errno, _("cannot create temporary file in %s"),
+ quoteaf (temp_dir));
free (node);
node = NULL;
}
else if (*how == 'w')
{
if (file && ftruncate (STDOUT_FILENO, 0) != 0)
- error (SORT_FAILURE, errno, _("%s: error truncating"),
- quotef (file));
+ die (SORT_FAILURE, errno, _("%s: error truncating"),
+ quotef (file));
fp = stdout;
}
else
{
FILE *fp = stream_open (file, how);
if (!fp)
- die (_("open failed"), file);
+ sort_die (_("open failed"), file);
return fp;
}
case STDOUT_FILENO:
/* Don't close stdout just yet. close_stdout does that. */
if (fflush (fp) != 0)
- die (_("fflush failed"), file);
+ sort_die (_("fflush failed"), file);
break;
default:
if (fclose (fp) != 0)
- die (_("close failed"), file);
+ sort_die (_("close failed"), file);
break;
}
}
*pfp = fdopen (tempfd, "w");
if (! *pfp)
- die (_("couldn't create temporary file"), node->name);
+ sort_die (_("couldn't create temporary file"), node->name);
return node;
}
{
case -1:
if (errno != EMFILE)
- error (SORT_FAILURE, errno, _("couldn't create process for %s -d"),
- quoteaf (compress_program));
+ die (SORT_FAILURE, errno, _("couldn't create process for %s -d"),
+ quoteaf (compress_program));
close (tempfd);
errno = EMFILE;
break;
{
error (0, 0, _("invalid --%s argument %s"),
long_options[oi].name, quote (s));
- error (SORT_FAILURE, 0,
- _("minimum --%s argument is %s"),
- long_options[oi].name, quote ("2"));
+ die (SORT_FAILURE, 0,
+ _("minimum --%s argument is %s"),
+ long_options[oi].name, quote ("2"));
}
else if (max_nmerge < nmerge)
{
char max_nmerge_buf[INT_BUFSIZE_BOUND (max_nmerge)];
error (0, 0, _("--%s argument %s too large"),
long_options[oi].name, quote (s));
- error (SORT_FAILURE, 0,
- _("maximum --%s argument with current rlimit is %s"),
- long_options[oi].name,
- uinttostr (max_nmerge, max_nmerge_buf));
+ die (SORT_FAILURE, 0,
+ _("maximum --%s argument with current rlimit is %s"),
+ long_options[oi].name,
+ uinttostr (max_nmerge, max_nmerge_buf));
}
else
xstrtol_fatal (e, oi, c, long_options, s);
if (SIZE_MAX < nthreads)
nthreads = SIZE_MAX;
if (nthreads == 0)
- error (SORT_FAILURE, 0, _("number in parallel must be nonzero"));
+ die (SORT_FAILURE, 0, _("number in parallel must be nonzero"));
return nthreads;
}
: STREQ (files[i], "-") ? fstat (STDIN_FILENO, &st)
: stat (files[i], &st))
!= 0)
- die (_("stat failed"), files[i]);
+ sort_die (_("stat failed"), files[i]);
if (S_ISREG (st.st_mode))
file_size = st.st_size;
if (bytes_read != readsize)
{
if (ferror (fp))
- die (_("read failed"), file);
+ sort_die (_("read failed"), file);
if (feof (fp))
{
buf->eof = true;
unsigned char buf[MD5_DIGEST_SIZE];
struct randread_source *r = randread_new (random_source, sizeof buf);
if (! r)
- die (_("open failed"), random_source);
+ sort_die (_("open failed"), random_source);
randread (r, buf, sizeof buf);
if (randread_free (r) != 0)
- die (_("close failed"), random_source);
+ sort_die (_("close failed"), random_source);
md5_init_ctx (&random_md5_state);
md5_process_bytes (buf, sizeof buf, &random_md5_state);
}
{
error (0, errno, _("string transformation failed"));
error (0, 0, _("set LC_ALL='C' to work around the problem"));
- error (SORT_FAILURE, 0,
- _("the untransformed string was %s"),
- quotearg_n_style (0, locale_quoting_style, src));
+ die (SORT_FAILURE, 0,
+ _("the untransformed string was %s"),
+ quotearg_n_style (0, locale_quoting_style, src));
}
return translated_size;
else if (c == ebuf)
wc = '\n';
if (fputc (wc, fp) == EOF)
- die (_("write failed"), output_file);
+ sort_die (_("write failed"), output_file);
}
debug_line (line);
{
ebuf[-1] = eolchar;
if (fwrite (buf, 1, n_bytes, fp) != n_bytes)
- die (_("write failed"), output_file);
+ sort_die (_("write failed"), output_file);
ebuf[-1] = '\0';
}
}
FILE **fps;
size_t nopened = open_input_files (files, nfiles, &fps);
if (nopened < nfiles && nopened < 2)
- die (_("open failed"), files[nopened].name);
+ sort_die (_("open failed"), files[nopened].name);
mergefps (files, ntemps, nopened, ofp, output_file, fps);
return nopened;
}
continue;
if (euidaccess (files[i], R_OK) != 0)
- die (_("cannot read"), files[i]);
+ sort_die (_("cannot read"), files[i]);
}
}
{
int outfd = open (outfile, O_WRONLY | O_CREAT | O_BINARY, MODE_RW_UGO);
if (outfd < 0)
- die (_("open failed"), outfile);
+ sort_die (_("open failed"), outfile);
move_fd_or_die (outfd, STDOUT_FILENO);
}
}
break;
}
if (errno != EMFILE || nopened <= 2)
- die (_("open failed"), output_file);
+ sort_die (_("open failed"), output_file);
}
else if (nopened <= 2)
- die (_("open failed"), files[nopened].name);
+ sort_die (_("open failed"), files[nopened].name);
/* We ran out of file descriptors. Close one of the input
files, to gain a file descriptor. Then create a temporary
static void
badfieldspec (char const *spec, char const *msgid)
{
- error (SORT_FAILURE, 0, _("%s: invalid field specification %s"),
- _(msgid), quote (spec));
+ die (SORT_FAILURE, 0, _("%s: invalid field specification %s"),
+ _(msgid), quote (spec));
abort ();
}
static void
incompatible_options (char const *opts)
{
- error (SORT_FAILURE, 0, _("options '-%s' are incompatible"), (opts));
+ die (SORT_FAILURE, 0, _("options '-%s' are incompatible"), (opts));
abort ();
}
case LONGINT_INVALID:
if (msgid)
- error (SORT_FAILURE, 0, _("%s: invalid count at start of %s"),
- _(msgid), quote (string));
+ die (SORT_FAILURE, 0, _("%s: invalid count at start of %s"),
+ _(msgid), quote (string));
return NULL;
}
case COMPRESS_PROGRAM_OPTION:
if (compress_program && !STREQ (compress_program, optarg))
- error (SORT_FAILURE, 0, _("multiple compress programs specified"));
+ die (SORT_FAILURE, 0, _("multiple compress programs specified"));
compress_program = optarg;
break;
case 'o':
if (outfile && !STREQ (outfile, optarg))
- error (SORT_FAILURE, 0, _("multiple output files specified"));
+ die (SORT_FAILURE, 0, _("multiple output files specified"));
outfile = optarg;
break;
case RANDOM_SOURCE_OPTION:
if (random_source && !STREQ (random_source, optarg))
- error (SORT_FAILURE, 0, _("multiple random sources specified"));
+ die (SORT_FAILURE, 0, _("multiple random sources specified"));
random_source = optarg;
break;
{
char newtab = optarg[0];
if (! newtab)
- error (SORT_FAILURE, 0, _("empty tab"));
+ die (SORT_FAILURE, 0, _("empty tab"));
if (optarg[1])
{
if (STREQ (optarg, "\\0"))
"multi-character tab" instead of "multibyte tab", so
that the diagnostic's wording does not need to be
changed once multibyte characters are supported. */
- error (SORT_FAILURE, 0, _("multi-character tab %s"),
- quote (optarg));
+ die (SORT_FAILURE, 0, _("multi-character tab %s"),
+ quote (optarg));
}
}
if (tab != TAB_DEFAULT && tab != newtab)
- error (SORT_FAILURE, 0, _("incompatible tabs"));
+ die (SORT_FAILURE, 0, _("incompatible tabs"));
tab = newtab;
}
break;
{
stream = fopen (files_from, "r");
if (stream == NULL)
- error (SORT_FAILURE, errno, _("cannot open %s for reading"),
- quoteaf (files_from));
+ die (SORT_FAILURE, errno, _("cannot open %s for reading"),
+ quoteaf (files_from));
}
readtokens0_init (&tok);
if (! readtokens0 (stream, &tok) || fclose (stream) != 0)
- error (SORT_FAILURE, 0, _("cannot read file names from %s"),
- quoteaf (files_from));
+ die (SORT_FAILURE, 0, _("cannot read file names from %s"),
+ quoteaf (files_from));
if (tok.n_tok)
{
for (i = 0; i < nfiles; i++)
{
if (STREQ (files[i], "-"))
- error (SORT_FAILURE, 0, _("when reading file names from stdin, "
- "no file name of %s allowed"),
- quoteaf (files[i]));
+ die (SORT_FAILURE, 0, _("when reading file names from stdin, "
+ "no file name of %s allowed"),
+ quoteaf (files[i]));
else if (files[i][0] == '\0')
{
/* Using the standard 'filename:line-number:' prefix here is
not totally appropriate, since NUL is the separator,
not NL, but it might be better than nothing. */
unsigned long int file_number = i + 1;
- error (SORT_FAILURE, 0,
- _("%s:%lu: invalid zero-length file name"),
- quotef (files_from), file_number);
+ die (SORT_FAILURE, 0,
+ _("%s:%lu: invalid zero-length file name"),
+ quotef (files_from), file_number);
}
}
}
else
- error (SORT_FAILURE, 0, _("no input from %s"),
- quoteaf (files_from));
+ die (SORT_FAILURE, 0, _("no input from %s"),
+ quoteaf (files_from));
}
/* Inheritance of global options to individual keys. */
if (checkonly)
{
if (nfiles > 1)
- error (SORT_FAILURE, 0, _("extra operand %s not allowed with -%c"),
- quoteaf (files[1]), checkonly);
+ die (SORT_FAILURE, 0, _("extra operand %s not allowed with -%c"),
+ quoteaf (files[1]), checkonly);
if (outfile)
{
#endif
if (have_read_stdin && fclose (stdin) == EOF)
- die (_("close failed"), "-");
+ sort_die (_("close failed"), "-");
return EXIT_SUCCESS;
}
#include <sys/wait.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "fd-reopen.h"
#include "fcntl--.h"
{
if (suffix_length < suffix_needed)
{
- error (EXIT_FAILURE, 0,
- _("the suffix length needs to be at least %"PRIuMAX),
- suffix_needed);
+ die (EXIT_FAILURE, 0,
+ _("the suffix length needs to be at least %"PRIuMAX),
+ suffix_needed);
}
suffix_auto = false;
return;
char *dir = dir_name (outfile);
long name_max = pathconf (dir, _PC_NAME_MAX);
if (0 <= name_max && name_max < base_len (last_component (outfile)))
- error (EXIT_FAILURE, ENAMETOOLONG, "%s", quotef (outfile));
+ die (EXIT_FAILURE, ENAMETOOLONG, "%s", quotef (outfile));
free (dir);
}
#endif
sufindex[i] = 0;
outfile_mid[i] = suffix_alphabet[sufindex[i]];
}
- error (EXIT_FAILURE, 0, _("output file suffixes exhausted"));
+ die (EXIT_FAILURE, 0, _("output file suffixes exhausted"));
}
}
return fd;
struct stat out_stat_buf;
if (fstat (fd, &out_stat_buf) != 0)
- error (EXIT_FAILURE, errno, _("failed to stat %s"), quoteaf (name));
+ die (EXIT_FAILURE, errno, _("failed to stat %s"), quoteaf (name));
if (SAME_INODE (in_stat_buf, out_stat_buf))
- error (EXIT_FAILURE, 0, _("%s would overwrite input; aborting"),
- quoteaf (name));
+ die (EXIT_FAILURE, 0, _("%s would overwrite input; aborting"),
+ quoteaf (name));
if (ftruncate (fd, 0) != 0)
- error (EXIT_FAILURE, errno, _("%s: error truncating"), quotef (name));
+ die (EXIT_FAILURE, errno, _("%s: error truncating"), quotef (name));
return fd;
}
if (shell_prog == NULL)
shell_prog = "/bin/sh";
if (setenv ("FILE", name, 1) != 0)
- error (EXIT_FAILURE, errno,
- _("failed to set FILE environment variable"));
+ die (EXIT_FAILURE, errno,
+ _("failed to set FILE environment variable"));
if (verbose)
fprintf (stdout, _("executing with FILE=%s\n"), quotef (name));
if (pipe (fd_pair) != 0)
- error (EXIT_FAILURE, errno, _("failed to create pipe"));
+ die (EXIT_FAILURE, errno, _("failed to create pipe"));
child_pid = fork ();
if (child_pid == 0)
{
reading an EOF on the corresponding read-pipe. */
for (j = 0; j < n_open_pipes; ++j)
if (close (open_pipes[j]) != 0)
- error (EXIT_FAILURE, errno, _("closing prior pipe"));
+ die (EXIT_FAILURE, errno, _("closing prior pipe"));
if (close (fd_pair[1]))
- error (EXIT_FAILURE, errno, _("closing output pipe"));
+ die (EXIT_FAILURE, errno, _("closing output pipe"));
if (fd_pair[0] != STDIN_FILENO)
{
if (dup2 (fd_pair[0], STDIN_FILENO) != STDIN_FILENO)
- error (EXIT_FAILURE, errno, _("moving input pipe"));
+ die (EXIT_FAILURE, errno, _("moving input pipe"));
if (close (fd_pair[0]) != 0)
- error (EXIT_FAILURE, errno, _("closing input pipe"));
+ die (EXIT_FAILURE, errno, _("closing input pipe"));
}
sigprocmask (SIG_SETMASK, &oldblocked, NULL);
execl (shell_prog, last_component (shell_prog), "-c",
filter_command, (char *) NULL);
- error (EXIT_FAILURE, errno, _("failed to run command: \"%s -c %s\""),
- shell_prog, filter_command);
+ die (EXIT_FAILURE, errno, _("failed to run command: \"%s -c %s\""),
+ shell_prog, filter_command);
}
if (child_pid == -1)
- error (EXIT_FAILURE, errno, _("fork system call failed"));
+ die (EXIT_FAILURE, errno, _("fork system call failed"));
if (close (fd_pair[0]) != 0)
- error (EXIT_FAILURE, errno, _("failed to close input pipe"));
+ die (EXIT_FAILURE, errno, _("failed to close input pipe"));
filter_pid = child_pid;
if (n_open_pipes == open_pipes_alloc)
open_pipes = x2nrealloc (open_pipes, &open_pipes_alloc,
closeout (FILE *fp, int fd, pid_t pid, char const *name)
{
if (fp != NULL && fclose (fp) != 0 && ! ignorable (errno))
- error (EXIT_FAILURE, errno, "%s", quotef (name));
+ die (EXIT_FAILURE, errno, "%s", quotef (name));
if (fd >= 0)
{
if (fp == NULL && close (fd) < 0)
- error (EXIT_FAILURE, errno, "%s", quotef (name));
+ die (EXIT_FAILURE, errno, "%s", quotef (name));
int j;
for (j = 0; j < n_open_pipes; ++j)
{
{
int wstatus = 0;
if (waitpid (pid, &wstatus, 0) == -1 && errno != ECHILD)
- error (EXIT_FAILURE, errno, _("waiting for child process"));
+ die (EXIT_FAILURE, errno, _("waiting for child process"));
if (WIFSIGNALED (wstatus))
{
int sig = WTERMSIG (wstatus);
else
{
/* shouldn't happen. */
- error (EXIT_FAILURE, 0,
- _("unknown status from command (0x%X)"), wstatus + 0u);
+ die (EXIT_FAILURE, 0,
+ _("unknown status from command (0x%X)"), wstatus + 0u);
}
}
}
next_file_name ();
output_desc = create (outfile);
if (output_desc < 0)
- error (EXIT_FAILURE, errno, "%s", quotef (outfile));
+ die (EXIT_FAILURE, errno, "%s", quotef (outfile));
}
if (full_write (output_desc, bp, bytes) == bytes)
else
{
if (! ignorable (errno))
- error (EXIT_FAILURE, errno, "%s", quotef (outfile));
+ die (EXIT_FAILURE, errno, "%s", quotef (outfile));
return false;
}
}
{
n_read = safe_read (STDIN_FILENO, buf, bufsize);
if (n_read == SAFE_READ_ERROR)
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
eof = n_read == 0;
}
char *bp_out = buf;
{
n_read = safe_read (STDIN_FILENO, buf, bufsize);
if (n_read == SAFE_READ_ERROR)
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
bp = bp_out = buf;
eob = bp + n_read;
*eob = eolchar;
{
n_read = safe_read (STDIN_FILENO, buf, bufsize);
if (n_read == SAFE_READ_ERROR)
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
size_t n_left = n_read;
char *sob = buf;
while (n_left)
else
{
if (lseek (STDIN_FILENO, start - initial_read, SEEK_CUR) < 0)
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
initial_read = SIZE_MAX;
}
n_written = start;
{
n_read = safe_read (STDIN_FILENO, buf, bufsize);
if (n_read == SAFE_READ_ERROR)
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
}
if (n_read == 0)
break; /* eof. */
large chunks from an existing file, so it's more efficient
to write out directly. */
if (full_write (STDOUT_FILENO, bp, to_write) != to_write)
- error (EXIT_FAILURE, errno, "%s", _("write error"));
+ die (EXIT_FAILURE, errno, "%s", _("write error"));
}
else if (! k)
cwrite (new_file_flag, bp, to_write);
else
{
if (lseek (STDIN_FILENO, start, SEEK_CUR) < 0)
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
initial_read = SIZE_MAX;
}
{
n_read = safe_read (STDIN_FILENO, buf, bufsize);
if (n_read == SAFE_READ_ERROR)
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
}
if (n_read == 0)
break; /* eof. */
n_read = MIN (n_read, end - start);
if (full_write (STDOUT_FILENO, buf, n_read) != n_read
&& ! ignorable (errno))
- error (EXIT_FAILURE, errno, "%s", quotef ("-"));
+ die (EXIT_FAILURE, errno, "%s", quotef ("-"));
start += n_read;
}
}
break;
if (!(errno == EMFILE || errno == ENFILE))
- error (EXIT_FAILURE, errno, "%s", quotef (files[i_check].of_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (files[i_check].of_name));
file_limit = true;
i_reopen = i_reopen ? i_reopen - 1 : nfiles - 1;
/* No more open files to close, exit with E[NM]FILE. */
if (i_reopen == i_check)
- error (EXIT_FAILURE, errno, "%s",
- quotef (files[i_check].of_name));
+ die (EXIT_FAILURE, errno, "%s",
+ quotef (files[i_check].of_name));
}
if (fclose (files[i_reopen].ofile) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (files[i_reopen].of_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (files[i_reopen].of_name));
files[i_reopen].ofile = NULL;
files[i_reopen].ofd = OFD_APPEND;
}
files[i_check].ofd = fd;
if (!(files[i_check].ofile = fdopen (fd, "a")))
- error (EXIT_FAILURE, errno, "%s", quotef (files[i_check].of_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (files[i_check].of_name));
files[i_check].opid = filter_pid;
filter_pid = 0;
}
char *bp = buf, *eob;
size_t n_read = safe_read (STDIN_FILENO, buf, bufsize);
if (n_read == SAFE_READ_ERROR)
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
else if (n_read == 0)
break; /* eof. */
eob = buf + n_read;
if (line_no == k && unbuffered)
{
if (full_write (STDOUT_FILENO, bp, to_write) != to_write)
- error (EXIT_FAILURE, errno, "%s", _("write error"));
+ die (EXIT_FAILURE, errno, "%s", _("write error"));
}
else if (line_no == k && fwrite (bp, to_write, 1, stdout) != 1)
{
clearerr (stdout); /* To silence close_stdout(). */
- error (EXIT_FAILURE, errno, "%s", _("write error"));
+ die (EXIT_FAILURE, errno, "%s", _("write error"));
}
if (next)
line_no = (line_no == n) ? 1 : line_no + 1;
if (full_write (files[i_file].ofd, bp, to_write) != to_write
&& ! ignorable (errno))
{
- error (EXIT_FAILURE, errno, "%s",
- quotef (files[i_file].of_name));
+ die (EXIT_FAILURE, errno, "%s",
+ quotef (files[i_file].of_name));
}
}
else if (fwrite (bp, to_write, 1, files[i_file].ofile) != 1
&& ! ignorable (errno))
{
- error (EXIT_FAILURE, errno, "%s",
- quotef (files[i_file].of_name));
+ die (EXIT_FAILURE, errno, "%s",
+ quotef (files[i_file].of_name));
}
if (! ignorable (errno))
{
if (fclose (files[i_file].ofile) != 0)
{
- error (EXIT_FAILURE, errno, "%s",
- quotef (files[i_file].of_name));
+ die (EXIT_FAILURE, errno, "%s",
+ quotef (files[i_file].of_name));
}
files[i_file].ofile = NULL;
files[i_file].ofd = OFD_APPEND;
{
char neweol = optarg[0];
if (! neweol)
- error (EXIT_FAILURE, 0, _("empty record separator"));
+ die (EXIT_FAILURE, 0, _("empty record separator"));
if (optarg[1])
{
if (STREQ (optarg, "\\0"))
"multi-character tab" instead of "multibyte tab", so
that the diagnostic's wording does not need to be
changed once multibyte characters are supported. */
- error (EXIT_FAILURE, 0, _("multi-character separator %s"),
- quote (optarg));
+ die (EXIT_FAILURE, 0, _("multi-character separator %s"),
+ quote (optarg));
}
}
/* Make it explicit we don't support multiple separators. */
if (0 <= eolchar && neweol != eolchar)
{
- error (EXIT_FAILURE, 0,
- _("multiple separator characters specified"));
+ die (EXIT_FAILURE, 0,
+ _("multiple separator characters specified"));
}
eolchar = neweol;
if (!DECIMAL_DIGIT_ACCUMULATE (n_units, c - '0', uintmax_t))
{
char buffer[INT_BUFSIZE_BOUND (uintmax_t)];
- error (EXIT_FAILURE, 0,
- _("line count option -%s%c... is too large"),
- umaxtostr (n_units, buffer), c);
+ die (EXIT_FAILURE, 0,
+ _("line count option -%s%c... is too large"),
+ umaxtostr (n_units, buffer), c);
}
break;
/* Open the input file. */
if (! STREQ (infile, "-")
&& fd_reopen (STDIN_FILENO, infile, O_RDONLY, 0) < 0)
- error (EXIT_FAILURE, errno, _("cannot open %s for reading"),
- quoteaf (infile));
+ die (EXIT_FAILURE, errno, _("cannot open %s for reading"),
+ quoteaf (infile));
/* Binary I/O is safer when byte counts are used. */
if (O_BINARY && ! isatty (STDIN_FILENO))
/* Get the optimal block size of input device and make a buffer. */
if (fstat (STDIN_FILENO, &in_stat_buf) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
bool specified_buf_size = !! in_blk_size;
if (! specified_buf_size)
file_size = input_file_size (STDIN_FILENO, &in_stat_buf,
buf, in_blk_size);
if (file_size < 0)
- error (EXIT_FAILURE, errno, _("%s: cannot determine file size"),
- quotef (infile));
+ die (EXIT_FAILURE, errno, _("%s: cannot determine file size"),
+ quotef (infile));
initial_read = MIN (file_size, in_blk_size);
/* Overflow, and sanity checking. */
if (OFF_T_MAX < n_units)
{
char buffer[INT_BUFSIZE_BOUND (uintmax_t)];
- error (EXIT_FAILURE, EOVERFLOW, "%s: %s",
- _("invalid number of chunks"),
- quote (umaxtostr (n_units, buffer)));
+ die (EXIT_FAILURE, EOVERFLOW, "%s: %s",
+ _("invalid number of chunks"),
+ quote (umaxtostr (n_units, buffer)));
}
/* increase file_size to n_units here, so that we still process
any input data, and create empty files for the rest. */
IF_LINT (free (b));
if (close (STDIN_FILENO) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
closeout (NULL, output_desc, filter_pid, outfile);
return EXIT_SUCCESS;
#include "system.h"
#include "areadlink.h"
+#include "die.h"
#include "error.h"
#include "file-type.h"
#include "filemode.h"
{
dest[len + 1] = *fmt_char;
dest[len + 2] = '\0';
- error (EXIT_FAILURE, 0, _("%s: invalid directive"),
- quote (dest));
+ die (EXIT_FAILURE, 0, _("%s: invalid directive"),
+ quote (dest));
}
putchar ('%');
break;
#include <assert.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "filenamecat.h"
#include "quote.h"
++path;
if ( ! *path)
- error (EXIT_CANCELED, 0, _("failed to find %s"), quote (LIB_NAME));
+ die (EXIT_CANCELED, 0, _("failed to find %s"), quote (LIB_NAME));
}
/* FIXME: Do we need to support libstdbuf.dll, c:, '\' separators etc? */
if (ret != 0)
{
- error (EXIT_CANCELED, errno,
- _("failed to update the environment with %s"),
- quote (LD_PRELOAD));
+ die (EXIT_CANCELED, errno,
+ _("failed to update the environment with %s"),
+ quote (LD_PRELOAD));
}
}
if (putenv (var) != 0)
{
- error (EXIT_CANCELED, errno,
- _("failed to update the environment with %s"),
- quote (var));
+ die (EXIT_CANCELED, errno,
+ _("failed to update the environment with %s"),
+ quote (var));
}
env_set = true;
if (!STREQ (optarg, "L")
&& parse_size (optarg, &stdbuf[opt_fileno].size) == -1)
- error (EXIT_CANCELED, errno, _("invalid mode %s"), quote (optarg));
+ die (EXIT_CANCELED, errno, _("invalid mode %s"), quote (optarg));
break;
#include <assert.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "fd-reopen.h"
#include "quote.h"
case 'F':
if (file_name)
- error (EXIT_FAILURE, 0, _("only one device may be specified"));
+ die (EXIT_FAILURE, 0, _("only one device may be specified"));
file_name = optarg;
break;
/* Specifying both -a and -g gets an error. */
if (verbose_output && recoverable_output)
- error (EXIT_FAILURE, 0,
- _("the options for verbose and stty-readable output styles are\n"
- "mutually exclusive"));
+ die (EXIT_FAILURE, 0,
+ _("the options for verbose and stty-readable output styles are\n"
+ "mutually exclusive"));
/* Specifying any other arguments with -a or -g gets an error. */
if (!noargs && (verbose_output || recoverable_output))
- error (EXIT_FAILURE, 0,
- _("when specifying an output style, modes may not be set"));
+ die (EXIT_FAILURE, 0,
+ _("when specifying an output style, modes may not be set"));
/* FIXME: it'd be better not to open the file until we've verified
that all arguments are valid. Otherwise, we could end up doing
int fdflags;
device_name = file_name;
if (fd_reopen (STDIN_FILENO, device_name, O_RDONLY | O_NONBLOCK, 0) < 0)
- error (EXIT_FAILURE, errno, "%s", quotef (device_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (device_name));
if ((fdflags = fcntl (STDIN_FILENO, F_GETFL)) == -1
|| fcntl (STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
- error (EXIT_FAILURE, errno, _("%s: couldn't reset non-blocking mode"),
- quotef (device_name));
+ die (EXIT_FAILURE, errno, _("%s: couldn't reset non-blocking mode"),
+ quotef (device_name));
}
else
device_name = _("standard input");
if (tcgetattr (STDIN_FILENO, &mode))
- error (EXIT_FAILURE, errno, "%s", quotef (device_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (device_name));
if (verbose_output || recoverable_output || noargs)
{
if (ioctl (STDIN_FILENO, TIOCEXT, &val) != 0)
{
- error (EXIT_FAILURE, errno, _("%s: error setting %s"),
- quotef_n (0, device_name), quote_n (1, arg));
+ die (EXIT_FAILURE, errno, _("%s: error setting %s"),
+ quotef_n (0, device_name), quote_n (1, arg));
}
}
#endif
static struct termios new_mode;
if (tcsetattr (STDIN_FILENO, tcsetattr_options, &mode))
- error (EXIT_FAILURE, errno, "%s", quotef (device_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (device_name));
/* POSIX (according to Zlotnick's book) tcsetattr returns zero if
it performs *any* of the requested operations. This means it
compare them to the requested ones. */
if (tcgetattr (STDIN_FILENO, &new_mode))
- error (EXIT_FAILURE, errno, "%s", quotef (device_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (device_name));
/* Normally, one shouldn't use memcmp to compare structures that
may have 'holes' containing uninitialized data, but we have been
if (speed_was_set || memcmp (&mode, &new_mode, sizeof (mode)) != 0)
#endif
{
- error (EXIT_FAILURE, 0,
- _("%s: unable to perform all requested operations"),
- quotef (device_name));
+ die (EXIT_FAILURE, 0,
+ _("%s: unable to perform all requested operations"),
+ quotef (device_name));
#ifdef TESTING
{
size_t i;
if (get_win_size (STDIN_FILENO, &win))
{
if (errno != EINVAL)
- error (EXIT_FAILURE, errno, "%s", quotef (device_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (device_name));
memset (&win, 0, sizeof (win));
}
win.ws_col = 1;
if (ioctl (STDIN_FILENO, TIOCSWINSZ, (char *) &win))
- error (EXIT_FAILURE, errno, "%s", quotef (device_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (device_name));
if (ioctl (STDIN_FILENO, TIOCSSIZE, (char *) &ttysz))
- error (EXIT_FAILURE, errno, "%s", quotef (device_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (device_name));
return;
}
# endif
if (ioctl (STDIN_FILENO, TIOCSWINSZ, (char *) &win))
- error (EXIT_FAILURE, errno, "%s", quotef (device_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (device_name));
}
static void
if (get_win_size (STDIN_FILENO, &win))
{
if (errno != EINVAL)
- error (EXIT_FAILURE, errno, "%s", quotef (device_name));
+ die (EXIT_FAILURE, errno, "%s", quotef (device_name));
if (!fancy)
- error (EXIT_FAILURE, 0,
- _("%s: no size information for this device"),
- quotef (device_name));
+ die (EXIT_FAILURE, 0,
+ _("%s: no size information for this device"),
+ quotef (device_name));
}
else
{
#include <sys/types.h>
#include <getopt.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "human.h"
ok &= sum_func (argv[optind], files_given);
if (have_read_stdin && fclose (stdin) == EOF)
- error (EXIT_FAILURE, errno, "%s", quotef ("-"));
+ die (EXIT_FAILURE, errno, "%s", quotef ("-"));
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
/* The official name of this program (e.g., no 'g' prefix). */
if (arg_data && arg_file_system)
{
- error (EXIT_FAILURE, 0,
- _("cannot specify both --data and --file-system"));
+ die (EXIT_FAILURE, 0,
+ _("cannot specify both --data and --file-system"));
}
if (!args_specified && arg_data)
- error (EXIT_FAILURE, 0, _("--data needs at least one argument"));
+ die (EXIT_FAILURE, 0, _("--data needs at least one argument"));
if (! args_specified || (arg_file_system && ! HAVE_SYNCFS))
mode = MODE_SYNC;
/* FIXME */
#include <assert.h>
+#include "die.h"
+
/* FIXME: this is small for testing */
#define BUFFER_SIZE (8)
}
bytes_read = full_read (STDIN_FILENO, buf, BUFFER_SIZE);
if (bytes_read != buffer_size && errno != 0)
- error (EXIT_FAILURE, errno, _("read error"));
+ die (EXIT_FAILURE, errno, _("read error"));
{
struct B_pair bp;
#include <regex.h>
+#include "die.h"
#include "error.h"
#include "filenamecat.h"
#include "safe-read.h"
regoff_t ret;
if (1 < range)
- error (EXIT_FAILURE, 0, _("record too large"));
+ die (EXIT_FAILURE, 0, _("record too large"));
if (range == 1
|| ((ret = re_search (&compiled_separator, G_buffer,
match_start = G_buffer - 1;
else if (ret == -2)
{
- error (EXIT_FAILURE, 0,
- _("error in regular expression search"));
+ die (EXIT_FAILURE, 0,
+ _("error in regular expression search"));
}
else
{
if (sentinel_length == 0)
{
if (*separator == 0)
- error (EXIT_FAILURE, 0, _("separator cannot be empty"));
+ die (EXIT_FAILURE, 0, _("separator cannot be empty"));
compiled_separator.buffer = NULL;
compiled_separator.allocated = 0;
error_message = re_compile_pattern (separator, strlen (separator),
&compiled_separator);
if (error_message)
- error (EXIT_FAILURE, 0, "%s", (error_message));
+ die (EXIT_FAILURE, 0, "%s", (error_message));
}
else
match_length = sentinel_length = *separator ? strlen (separator) : 1;
if (n_bytes > 0 && fwrite (buffer, 1, n_bytes, stdout) < n_bytes)
{
clearerr (stdout); /* To avoid redundant close_stdout diagnostic. */
- error (EXIT_FAILURE, errno, _("error writing %s"),
- quoteaf ("standard output"));
+ die (EXIT_FAILURE, errno, _("error writing %s"),
+ quoteaf ("standard output"));
}
}
if (bytes_read == SAFE_READ_ERROR)
{
if (errno != EAGAIN)
- error (EXIT_FAILURE, errno, _("error reading %s"),
- quoteaf (pretty_filename));
+ die (EXIT_FAILURE, errno, _("error reading %s"),
+ quoteaf (pretty_filename));
break;
}
if (bytes_read == 0)
the append-only attribute. */
}
else
- error (EXIT_FAILURE, errno,
- _("%s: cannot change nonblocking mode"),
- quotef (name));
+ die (EXIT_FAILURE, errno,
+ _("%s: cannot change nonblocking mode"),
+ quotef (name));
}
else
f[i].blocking = blocking;
}
if ((!any_input || blocking) && fflush (stdout) != 0)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
/* If nothing was read, sleep and/or check for dead writers. */
if (!any_input)
&& errno != EPERM);
if (!writer_is_dead && xnanosleep (sleep_interval))
- error (EXIT_FAILURE, errno, _("cannot read realtime clock"));
+ die (EXIT_FAILURE, errno, _("cannot read realtime clock"));
}
}
fspec->size += bytes_read;
if (fflush (stdout) != 0)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
}
/* Attempt to tail N_FILES files forever, or until killed.
if (file_change == 0)
continue;
else if (file_change == -1)
- error (EXIT_FAILURE, errno, _("error monitoring inotify event"));
+ die (EXIT_FAILURE, errno, _("error monitoring inotify event"));
}
if (len <= evbuf_off)
}
if (len == 0 || len == SAFE_READ_ERROR)
- error (EXIT_FAILURE, errno, _("error reading inotify event"));
+ die (EXIT_FAILURE, errno, _("error reading inotify event"));
}
void_ev = evbuf + evbuf_off;
& ~LONGINT_INVALID_SUFFIX_CHAR)
!= LONGINT_OK)
{
- error (EXIT_FAILURE, errno, "%s: %s", _("invalid number"),
- quote (argv[1]));
+ die (EXIT_FAILURE, errno, "%s: %s", _("invalid number"),
+ quote (argv[1]));
}
/* Set globals. */
{
double s;
if (! (xstrtod (optarg, NULL, &s, c_strtod) && 0 <= s))
- error (EXIT_FAILURE, 0,
- _("invalid number of seconds: %s"), quote (optarg));
+ die (EXIT_FAILURE, 0,
+ _("invalid number of seconds: %s"), quote (optarg));
*sleep_interval = s;
}
break;
/* When following by name, there must be a name. */
if (found_hyphen && follow_mode == Follow_name)
- error (EXIT_FAILURE, 0, _("cannot follow %s by name"), quoteaf ("-"));
+ die (EXIT_FAILURE, 0, _("cannot follow %s by name"), quoteaf ("-"));
/* When following forever, warn if any file is '-'.
This is only a warning, since tail's output (before a failing seek,
tail_forever_inotify flushes only after writing,
not before reading. */
if (fflush (stdout) != 0)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
if (! tail_forever_inotify (wd, F, n_files, sleep_interval))
return EXIT_FAILURE;
IF_LINT (free (F));
if (have_read_stdin && close (STDIN_FILENO) < 0)
- error (EXIT_FAILURE, errno, "-");
+ die (EXIT_FAILURE, errno, "-");
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
#include "system.h"
#include "argmatch.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "stdio--.h"
ok = tee_files (argc - optind, &argv[optind]);
if (close (STDIN_FILENO) != 0)
- error (EXIT_FAILURE, errno, "%s", _("standard input"));
+ die (EXIT_FAILURE, errno, "%s", _("standard input"));
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
#include "system.h"
#include "argmatch.h"
+#include "die.h"
#include "error.h"
#include "fd-reopen.h"
#include "parse-datetime.h"
char const *flex_date, struct timespec const *now)
{
if (! parse_datetime (result, flex_date, now))
- error (EXIT_FAILURE, 0, _("invalid date format %s"), quote (flex_date));
+ die (EXIT_FAILURE, 0, _("invalid date format %s"), quote (flex_date));
}
/* Update the time of file FILE according to the options given.
case 't':
if (! posixtime (&newtime[0].tv_sec, optarg,
PDS_LEADING_YEAR | PDS_CENTURY | PDS_SECONDS))
- error (EXIT_FAILURE, 0, _("invalid date format %s"),
- quote (optarg));
+ die (EXIT_FAILURE, 0, _("invalid date format %s"),
+ quote (optarg));
newtime[0].tv_nsec = 0;
newtime[1] = newtime[0];
date_set = true;
might be an object-like macro. */
if (no_dereference ? lstat (ref_file, &ref_stats)
: stat (ref_file, &ref_stats))
- error (EXIT_FAILURE, errno,
- _("failed to get attributes of %s"), quoteaf (ref_file));
+ die (EXIT_FAILURE, errno,
+ _("failed to get attributes of %s"), quoteaf (ref_file));
newtime[0] = get_stat_atime (&ref_stats);
newtime[1] = get_stat_mtime (&ref_stats);
date_set = true;
#include <getopt.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "quote.h"
c1 must also transition at the same time. */
if (s2_new_element && class_s2 != UL_NONE
&& !(s1_new_element && class_s1 != UL_NONE))
- error (EXIT_FAILURE, 0,
- _("misaligned [:upper:] and/or [:lower:] construct"));
+ die (EXIT_FAILURE, 0,
+ _("misaligned [:upper:] and/or [:lower:] construct"));
/* If case converting, quickly skip over the elements. */
if (class_s2 != UL_NONE)
indefinite element. */
new_length = length + len;
if (! (length <= new_length && new_length <= REPEAT_COUNT_MAXIMUM))
- error (EXIT_FAILURE, 0, _("too many characters in set"));
+ die (EXIT_FAILURE, 0, _("too many characters in set"));
length = new_length;
}
tr '[:upper:]0-9' '[:lower:]'
That's not portable however, contradicts POSIX and is dependent
on your collating sequence. */
- error (EXIT_FAILURE, 0,
- _("when translating with string1 longer than string2,\nthe\
+ die (EXIT_FAILURE, 0,
+ _("when translating with string1 longer than string2,\nthe\
latter string must not end with a character class"));
abort (); /* inform gcc that the above use of error never returns. */
break;
get_s1_spec_stats (s1);
if (s1->n_indefinite_repeats > 0)
{
- error (EXIT_FAILURE, 0,
- _("the [c*] repeat construct may not appear in string1"));
+ die (EXIT_FAILURE, 0,
+ _("the [c*] repeat construct may not appear in string1"));
}
if (s2)
if (s2->n_indefinite_repeats > 1)
{
- error (EXIT_FAILURE, 0,
- _("only one [c*] repeat construct may appear in string2"));
+ die (EXIT_FAILURE, 0,
+ _("only one [c*] repeat construct may appear in string2"));
}
if (translating)
{
if (s2->has_equiv_class)
{
- error (EXIT_FAILURE, 0,
- _("[=c=] expressions may not appear in string2\
+ die (EXIT_FAILURE, 0,
+ _("[=c=] expressions may not appear in string2\
when translating"));
}
if (s2->has_restricted_char_class)
{
- error (EXIT_FAILURE, 0,
- _("when translating, the only character classes that may\
+ die (EXIT_FAILURE, 0,
+ _("when translating, the only character classes that may\
appear in\nstring2 are 'upper' and 'lower'"));
}
given or string1 is empty. */
if (s2->length == 0)
- error (EXIT_FAILURE, 0,
+ die (EXIT_FAILURE, 0,
_("when not truncating set1, string2 must be non-empty"));
string2_extend (s1, s2);
}
if (complement && s1->has_char_class
&& ! (s2->length == s1->length && homogeneous_spec_list (s2)))
{
- error (EXIT_FAILURE, 0,
- _("when translating with complemented character classes,\
+ die (EXIT_FAILURE, 0,
+ _("when translating with complemented character classes,\
\nstring2 must map all characters in the domain to one"));
}
}
/* Not translating. */
{
if (s2->n_indefinite_repeats > 0)
- error (EXIT_FAILURE, 0,
- _("the [c*] construct may appear in string2 only\
+ die (EXIT_FAILURE, 0,
+ _("the [c*] construct may appear in string2 only\
when translating"));
}
}
}
if (out_len > 0
&& fwrite (&buf[begin], 1, out_len, stdout) != out_len)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
}
if (char_to_squeeze != NOT_A_CHAR)
{
size_t nr = safe_read (STDIN_FILENO, buf, size);
if (nr == SAFE_READ_ERROR)
- error (EXIT_FAILURE, errno, _("read error"));
+ die (EXIT_FAILURE, errno, _("read error"));
return nr;
}
if (nr == 0)
break;
if (fwrite (io_buf, 1, nr, stdout) != nr)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
}
}
else if (squeeze_repeats && delete && non_option_args == 2)
if (bytes_read == 0)
break;
if (fwrite (io_buf, 1, bytes_read, stdout) != bytes_read)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
}
}
}
if (close (STDIN_FILENO) != 0)
- error (EXIT_FAILURE, errno, _("standard input"));
+ die (EXIT_FAILURE, errno, _("standard input"));
return EXIT_SUCCESS;
}
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "quote.h"
#include "stat-size.h"
_("Invalid number"), 0);
/* Rounding to multiple of 0 is nonsensical */
if ((rel_mode == rm_rup || rel_mode == rm_rdn) && size == 0)
- error (EXIT_FAILURE, 0, _("division by zero"));
+ die (EXIT_FAILURE, 0, _("division by zero"));
got_size = true;
break;
struct stat sb;
off_t file_size = -1;
if (stat (ref_file, &sb) != 0)
- error (EXIT_FAILURE, errno, _("cannot stat %s"), quoteaf (ref_file));
+ die (EXIT_FAILURE, errno, _("cannot stat %s"), quoteaf (ref_file));
if (usable_st_size (&sb))
file_size = sb.st_size;
else
}
}
if (file_size < 0)
- error (EXIT_FAILURE, errno, _("cannot get the size of %s"),
- quoteaf (ref_file));
+ die (EXIT_FAILURE, errno, _("cannot get the size of %s"),
+ quoteaf (ref_file));
if (!got_size)
size = file_size;
else
#include "system.h"
#include "long-options.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "readtokens.h"
root = new_item (NULL);
if (!is_stdin && ! freopen (file, "r", stdin))
- error (EXIT_FAILURE, errno, "%s", quotef (file));
+ die (EXIT_FAILURE, errno, "%s", quotef (file));
fadvise (stdin, FADVISE_SEQUENTIAL);
}
if (k != NULL)
- error (EXIT_FAILURE, 0, _("%s: input contains an odd number of tokens"),
- quotef (file));
+ die (EXIT_FAILURE, 0, _("%s: input contains an odd number of tokens"),
+ quotef (file));
/* T1. Initialize (N <- n). */
walk_tree (root, count_items);
IF_LINT (free (root));
if (fclose (stdin) != 0)
- error (EXIT_FAILURE, errno, "%s",
- is_stdin ? _("standard input") : quotef (file));
+ die (EXIT_FAILURE, errno, "%s",
+ is_stdin ? _("standard input") : quotef (file));
return ok;
}
#endif
#include "system.h"
+#include "die.h"
#include "error.h"
#include "quote.h"
#include "uname.h"
struct utsname name;
if (uname (&name) == -1)
- error (EXIT_FAILURE, errno, _("cannot get system name"));
+ die (EXIT_FAILURE, errno, _("cannot get system name"));
if (toprint & PRINT_KERNEL_NAME)
print_element (name.sysname);
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
-#include "error.h"
+#include "die.h"
#include "xstrndup.h"
#include "expand-common.h"
if (convert)
{
if (next_tab_column < column)
- error (EXIT_FAILURE, 0, _("input line is too long"));
+ die (EXIT_FAILURE, 0, _("input line is too long"));
if (c == '\t')
{
{
column++;
if (!column)
- error (EXIT_FAILURE, 0, _("input line is too long"));
+ die (EXIT_FAILURE, 0, _("input line is too long"));
}
if (pending)
if (pending > 1 && one_blank_before_tab_stop)
pending_blank[0] = '\t';
if (fwrite (pending_blank, 1, pending, stdout) != pending)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
pending = 0;
one_blank_before_tab_stop = false;
}
}
if (putchar (c) < 0)
- error (EXIT_FAILURE, errno, _("write error"));
+ die (EXIT_FAILURE, errno, _("write error"));
}
while (c != '\n');
}
have_tabval = true;
}
if (!DECIMAL_DIGIT_ACCUMULATE (tabval, c - '0', uintmax_t))
- error (EXIT_FAILURE, 0, _("tab stop value is too large"));
+ die (EXIT_FAILURE, 0, _("tab stop value is too large"));
break;
}
}
#include "system.h"
#include "argmatch.h"
#include "linebuffer.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "hard-locale.h"
break;
default:
- error (EXIT_FAILURE, 0, "%s: %s", opt, _(msgid));
+ die (EXIT_FAILURE, 0, "%s: %s", opt, _(msgid));
}
return MIN (size, SIZE_MAX);
struct linebuffer *thisline, *prevline;
if (! (STREQ (infile, "-") || freopen (infile, "r", stdin)))
- error (EXIT_FAILURE, errno, "%s", quotef (infile));
+ die (EXIT_FAILURE, errno, "%s", quotef (infile));
if (! (STREQ (outfile, "-") || freopen (outfile, "w", stdout)))
- error (EXIT_FAILURE, errno, "%s", quotef (outfile));
+ die (EXIT_FAILURE, errno, "%s", quotef (outfile));
fadvise (stdin, FADVISE_SEQUENTIAL);
if (match_count == UINTMAX_MAX)
{
if (count_occurrences)
- error (EXIT_FAILURE, 0, _("too many repeated lines"));
+ die (EXIT_FAILURE, 0, _("too many repeated lines"));
match_count--;
}
closefiles:
if (ferror (stdin) || fclose (stdin) != 0)
- error (EXIT_FAILURE, 0, _("error reading %s"), quoteaf (infile));
+ die (EXIT_FAILURE, 0, _("error reading %s"), quoteaf (infile));
/* stdout is handled via the atexit-invoked close_stdout function. */
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "long-options.h"
#include "quote.h"
}
if (unlink (argv[optind]) != 0)
- error (EXIT_FAILURE, errno, _("cannot unlink %s"), quoteaf (argv[optind]));
+ die (EXIT_FAILURE, errno, _("cannot unlink %s"), quoteaf (argv[optind]));
return EXIT_SUCCESS;
}
#endif
#include "c-strtod.h"
+#include "die.h"
#include "error.h"
#include "long-options.h"
#include "quote.h"
#endif
{
if (boot_time == 0)
- error (EXIT_FAILURE, errno, _("couldn't get boot time"));
+ die (EXIT_FAILURE, errno, _("couldn't get boot time"));
uptime = time_now - boot_time;
}
updays = uptime / 86400;
#if HAVE_UTMPX_H || HAVE_UTMP_H
if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (filename));
+ die (EXIT_FAILURE, errno, "%s", quotef (filename));
#endif
print_uptime (n_users, utmp_buf);
#include <sys/types.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "long-options.h"
#include "quote.h"
STRUCT_UTMP *utmp_buf;
if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (filename));
+ die (EXIT_FAILURE, errno, "%s", quotef (filename));
list_entries_users (n_users, utmp_buf);
#include "system.h"
#include "argv-iter.h"
+#include "die.h"
#include "error.h"
#include "fadvise.h"
#include "mbchar.h"
{
stream = fopen (files_from, "r");
if (stream == NULL)
- error (EXIT_FAILURE, errno, _("cannot open %s for reading"),
- quoteaf (files_from));
+ die (EXIT_FAILURE, errno, _("cannot open %s for reading"),
+ quoteaf (files_from));
}
/* Read the file list into RAM if we can detect its size and that
read_tokens = true;
readtokens0_init (&tok);
if (! readtokens0 (stream, &tok) || fclose (stream) != 0)
- error (EXIT_FAILURE, 0, _("cannot read file names from %s"),
- quoteaf (files_from));
+ die (EXIT_FAILURE, 0, _("cannot read file names from %s"),
+ quoteaf (files_from));
files = tok.tok;
nfiles = tok.n_tok;
ai = argv_iter_init_argv (files);
free (fstatus);
if (have_read_stdin && close (STDIN_FILENO) != 0)
- error (EXIT_FAILURE, errno, "-");
+ die (EXIT_FAILURE, errno, "-");
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
}
#include "c-ctype.h"
#include "canon-host.h"
#include "readutmp.h"
+#include "die.h"
#include "error.h"
#include "hard-locale.h"
#include "quote.h"
STRUCT_UTMP *utmp_buf;
if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
- error (EXIT_FAILURE, errno, "%s", quotef (filename));
+ die (EXIT_FAILURE, errno, "%s", quotef (filename));
if (short_list)
list_entries_who (n_users, utmp_buf);
#include <getopt.h>
#include "system.h"
+#include "die.h"
#include "error.h"
#include "long-options.h"
#include "quote.h"
uid = geteuid ();
pw = (uid == NO_UID && errno ? NULL : getpwuid (uid));
if (!pw)
- {
- error (0, errno, _("cannot find name for user ID %lu"),
- (unsigned long int) uid);
- exit (EXIT_FAILURE);
- }
+ die (EXIT_FAILURE, errno, _("cannot find name for user ID %lu"),
+ (unsigned long int) uid);
puts (pw->pw_name);
return EXIT_SUCCESS;
}