1 /* Error handler for noninteractive utilities
2 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
4 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
7 /* Adjusted slightly by Erik Andersen <andersen@uclibc.org> */
15 libc_hidden_proto(strcmp)
16 libc_hidden_proto(strerror)
17 libc_hidden_proto(fprintf)
18 libc_hidden_proto(exit)
19 libc_hidden_proto(putc)
20 libc_hidden_proto(vfprintf)
21 libc_hidden_proto(fflush)
22 libc_hidden_proto(fputc)
23 libc_hidden_proto(__fputc_unlocked)
24 libc_hidden_proto(stdout)
25 libc_hidden_proto(stderr)
27 /* This variable is incremented each time `error' is called. */
28 unsigned int error_message_count = 0;
29 /* Sometimes we want to have at most one error per line. This
30 variable controls whether this mode is selected or not. */
31 int error_one_per_line;
32 /* If NULL, error will flush stdout, then print on stderr the program
33 name, a colon and a space. Otherwise, error will call this
34 function without parameters instead. */
35 /* void (*error_print_progname) (void) = NULL; */
37 extern __typeof(error) __error attribute_hidden;
38 void __error (int status, int errnum, const char *message, ...)
44 va_start (args, message);
45 vfprintf (stderr, message, args);
47 ++error_message_count;
49 fprintf (stderr, ": %s", strerror (errnum));
56 extern __typeof(error_at_line) __error_at_line attribute_hidden;
57 void __error_at_line (int status, int errnum, const char *file_name,
58 unsigned int line_number, const char *message, ...)
62 if (error_one_per_line) {
63 static const char *old_file_name;
64 static unsigned int old_line_number;
66 if (old_line_number == line_number &&
67 (file_name == old_file_name || !strcmp (old_file_name, file_name)))
68 /* Simply return and print nothing. */
71 old_file_name = file_name;
72 old_line_number = line_number;
77 if (file_name != NULL)
78 fprintf (stderr, "%s:%d: ", file_name, line_number);
80 va_start (args, message);
81 vfprintf (stderr, message, args);
84 ++error_message_count;
86 fprintf (stderr, ": %s", strerror (errnum));
93 /* psm: keep this weak, too many use this in common code */
94 weak_alias(__error,error)
95 strong_alias(__error_at_line,error_at_line)