/* Written by Paul Rubin, David MacKenzie, and Stuart Kemp. */
#include <config.h>
-#define _GL_NO_INLINE_ERROR /* Avoid gnulib's error macro. */
#include <sys/types.h>
#include <signal.h>
_exit (EXIT_FAILURE);
}
-/* Like the 'error' function but handle any pending newline. */
+/* Like the 'error' function but handle any pending newline,
+ and do not exit. */
-ATTRIBUTE_FORMAT ((__printf__, 3, 4))
+ATTRIBUTE_FORMAT ((__printf__, 2, 3))
static void
-nl_error (int status, int errnum, char const *fmt, ...)
+diagnose (int errnum, char const *fmt, ...)
{
if (0 < progress_len)
{
va_list ap;
va_start (ap, fmt);
- verror (status, errnum, fmt, ap);
+ verror (0, errnum, fmt, ap);
va_end (ap);
}
-#define error nl_error
-
void
usage (int status)
{
{
idx_t prev = prev_nread;
if (status_level != STATUS_NONE)
- error (0, 0, ngettext (("warning: partial read (%td byte); "
+ diagnose (0, ngettext (("warning: partial read (%td byte); "
"suggest iflag=fullblock"),
("warning: partial read (%td bytes); "
"suggest iflag=fullblock"),
select_plural (prev)),
- prev);
+ prev);
warn_partial_read = false;
}
}
int old_flags = fcntl (STDOUT_FILENO, F_GETFL);
if (fcntl (STDOUT_FILENO, F_SETFL, old_flags & ~O_DIRECT) != 0
&& status_level != STATUS_NONE)
- error (0, errno, _("failed to turn off O_DIRECT: %s"),
- quotef (output_file));
+ diagnose (errno, _("failed to turn off O_DIRECT: %s"),
+ quotef (output_file));
/* Since we have just turned off O_DIRECT for the final write,
we try to preserve some of its semantics. */
w_bytes += nwritten;
if (nwritten != output_blocksize)
{
- error (0, errno, _("writing to %s"), quoteaf (output_file));
+ diagnose (errno, _("writing to %s"), quoteaf (output_file));
if (nwritten != 0)
w_partial++;
quit (EXIT_FAILURE);
if (! entry->symbol[0])
{
idx_t slen = strcomma ? strcomma - str : strlen (str);
- error (0, 0, "%s: %s", _(error_msgid),
- quotearg_n_style_mem (0, locale_quoting_style, str, slen));
+ diagnose (0, "%s: %s", _(error_msgid),
+ quotearg_n_style_mem (0, locale_quoting_style,
+ str, slen));
usage (EXIT_FAILURE);
}
}
else
{
if (result == 0 && STRPREFIX (str, "0x"))
- error (0, 0,
- _("warning: %s is a zero multiplier; "
- "use %s if that is intended"),
- quote_n (0, "0x"), quote_n (1, "00x"));
+ diagnose (0, _("warning: %s is a zero multiplier; "
+ "use %s if that is intended"),
+ quote_n (0, "0x"), quote_n (1, "00x"));
e = LONGINT_OK;
}
}
if (val == NULL)
{
- error (0, 0, _("unrecognized operand %s"),
- quote (name));
+ diagnose (0, _("unrecognized operand %s"), quote (name));
usage (EXIT_FAILURE);
}
val++;
}
else
{
- error (0, 0, _("unrecognized operand %s"),
- quote (name));
+ diagnose (0, _("unrecognized operand %s"), quote (name));
usage (EXIT_FAILURE);
}
if (output_flags & O_FULLBLOCK)
{
- error (0, 0, "%s: %s", _("invalid output flag"), quote ("fullblock"));
+ diagnose (0, "%s: %s", _("invalid output flag"), quote ("fullblock"));
usage (EXIT_FAILURE);
}
lseek_errno = EOVERFLOW;
}
- if (fdesc == STDIN_FILENO)
- error (0, lseek_errno, _("%s: cannot skip"), quotef (file));
- else
- error (0, lseek_errno, _("%s: cannot seek"), quotef (file));
+ diagnose (lseek_errno,
+ gettext (fdesc == STDIN_FILENO
+ ? N_("%s: cannot skip")
+ : N_("%s: cannot seek")),
+ quotef (file));
/* If the file has a specific size and we've asked
to skip/seek beyond the max allowable, then quit. */
quit (EXIT_FAILURE);
{
if (fdesc == STDIN_FILENO)
{
- error (0, errno, _("error reading %s"), quoteaf (file));
+ diagnose (errno, _("error reading %s"), quoteaf (file));
if (conversions_mask & C_NOERROR)
print_stats ();
}
else
- error (0, lseek_errno, _("%s: cannot seek"), quotef (file));
+ diagnose (lseek_errno, _("%s: cannot seek"), quotef (file));
quit (EXIT_FAILURE);
}
else if (nread == 0)
advance_input_offset (nbytes);
if (input_offset < 0)
{
- error (0, 0, _("offset overflow while reading file %s"),
- quoteaf (input_file));
+ diagnose (0, _("offset overflow while reading file %s"),
+ quoteaf (input_file));
return false;
}
offset = lseek (STDIN_FILENO, 0, SEEK_CUR);
return true;
diff = input_offset - offset;
if (! (0 <= diff && diff <= nbytes) && status_level != STATUS_NONE)
- error (0, 0, _("warning: invalid file offset after failed read"));
+ diagnose (0, _("warning: invalid file offset after failed read"));
if (0 <= lseek (STDIN_FILENO, diff, SEEK_CUR))
return true;
if (errno == 0)
- error (0, 0, _("cannot work around kernel bug after all"));
+ diagnose (0, _("cannot work around kernel bug after all"));
}
}
- error (0, errno, _("%s: cannot seek"), quotef (input_file));
+ diagnose (errno, _("%s: cannot seek"), quotef (input_file));
return false;
}
|| us_bytes != input_offset - input_offset0)))
&& status_level != STATUS_NONE)
{
- error (0, 0,
- _("%s: cannot skip to specified offset"), quotef (input_file));
+ diagnose (0, _("%s: cannot skip to specified offset"),
+ quotef (input_file));
}
}
idx_t size = write_records ? output_blocksize : bytes;
if (iwrite (STDOUT_FILENO, obuf, size) != size)
{
- error (0, errno, _("writing to %s"), quoteaf (output_file));
+ diagnose (errno, _("writing to %s"), quoteaf (output_file));
quit (EXIT_FAILURE);
}
else
{
if (!(conversions_mask & C_NOERROR) || status_level != STATUS_NONE)
- error (0, errno, _("error reading %s"), quoteaf (input_file));
+ diagnose (errno, _("error reading %s"), quoteaf (input_file));
if (conversions_mask & C_NOERROR)
{
w_bytes += nwritten;
if (nwritten != n_bytes_read)
{
- error (0, errno, _("error writing %s"), quoteaf (output_file));
+ diagnose (errno, _("error writing %s"), quoteaf (output_file));
return EXIT_FAILURE;
}
else if (n_bytes_read == input_blocksize)
w_partial++;
if (nwritten != oc)
{
- error (0, errno, _("error writing %s"), quoteaf (output_file));
+ diagnose (errno, _("error writing %s"), quoteaf (output_file));
return EXIT_FAILURE;
}
}
struct stat stdout_stat;
if (ifstat (STDOUT_FILENO, &stdout_stat) != 0)
{
- error (0, errno, _("cannot fstat %s"), quoteaf (output_file));
+ diagnose (errno, _("cannot fstat %s"), quoteaf (output_file));
return EXIT_FAILURE;
}
if (S_ISREG (stdout_stat.st_mode) || S_TYPEISSHM (&stdout_stat))
{
if (iftruncate (STDOUT_FILENO, output_offset) != 0)
{
- error (0, errno,
- _("failed to truncate to %" PRIdMAX " bytes"
- " in output file %s"),
- (intmax_t) output_offset, quoteaf (output_file));
+ diagnose (errno, _("failed to truncate to %" PRIdMAX " bytes"
+ " in output file %s"),
+ (intmax_t) output_offset, quoteaf (output_file));
return EXIT_FAILURE;
}
}
{
if (errno != ENOSYS && errno != EINVAL)
{
- error (0, errno, _("fdatasync failed for %s"), quoteaf (output_file));
+ diagnose (errno, _("fdatasync failed for %s"), quoteaf (output_file));
exit_status = EXIT_FAILURE;
}
mask |= C_FSYNC;
if ((mask & C_FSYNC) && ifsync (STDOUT_FILENO) != 0)
{
- error (0, errno, _("fsync failed for %s"), quoteaf (output_file));
+ diagnose (errno, _("fsync failed for %s"), quoteaf (output_file));
return EXIT_FAILURE;
}
struct stat stdout_stat;
if (ifstat (STDOUT_FILENO, &stdout_stat) != 0)
{
- error (0, errno, _("cannot fstat %s"),
- quoteaf (output_file));
+ diagnose (errno, _("cannot fstat %s"), quoteaf (output_file));
exit_status = EXIT_FAILURE;
}
else if (S_ISREG (stdout_stat.st_mode)
|| S_TYPEISSHM (&stdout_stat))
{
intmax_t isize = size;
- error (0, ftruncate_errno,
- _("failed to truncate to %"PRIdMAX" bytes"
- " in output file %s"),
- isize, quoteaf (output_file));
+ diagnose (ftruncate_errno,
+ _("failed to truncate to %"PRIdMAX" bytes"
+ " in output file %s"),
+ isize, quoteaf (output_file));
exit_status = EXIT_FAILURE;
}
}
/* Special case to invalidate cache to end of file. */
if (i_nocache && !invalidate_cache (STDIN_FILENO, 0))
{
- error (0, errno, _("failed to discard cache for: %s"),
- quotef (input_file));
+ diagnose (errno, _("failed to discard cache for: %s"),
+ quotef (input_file));
exit_status = EXIT_FAILURE;
}
if (o_nocache && !invalidate_cache (STDOUT_FILENO, 0))
{
- error (0, errno, _("failed to discard cache for: %s"),
- quotef (output_file));
+ diagnose (errno, _("failed to discard cache for: %s"),
+ quotef (output_file));
exit_status = EXIT_FAILURE;
}
}