1 /* Error handler for noninteractive utilities
2 Copyright (C) 1990-1998, 2000-2004, 2005 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
21 /* Adjusted slightly by Erik Andersen <andersen@uclibc.org> */
29 /* Experimentally off - libc_hidden_proto(strcmp) */
30 /* Experimentally off - libc_hidden_proto(strerror) */
31 /* libc_hidden_proto(fprintf) */
32 /* libc_hidden_proto(exit) */
33 /* libc_hidden_proto(putc) */
34 /* libc_hidden_proto(vfprintf) */
35 /* libc_hidden_proto(fflush) */
36 /* libc_hidden_proto(fputc) */
37 /* libc_hidden_proto(__fputc_unlocked) */
39 /* This variable is incremented each time `error' is called. */
40 unsigned int error_message_count = 0;
41 /* Sometimes we want to have at most one error per line. This
42 variable controls whether this mode is selected or not. */
43 int error_one_per_line;
44 /* If NULL, error will flush stdout, then print on stderr the program
45 name, a colon and a space. Otherwise, error will call this
46 function without parameters instead. */
47 void (*error_print_progname) (void) = NULL;
49 extern __typeof(error) __error attribute_hidden;
50 void __error (int status, int errnum, const char *message, ...)
56 if (error_print_progname)
57 (*error_print_progname) ();
59 fprintf (stderr, "%s: ", __uclibc_progname);
61 va_start (args, message);
62 vfprintf (stderr, message, args);
64 ++error_message_count;
66 fprintf (stderr, ": %s", strerror (errnum));
72 weak_alias(__error,error)
74 extern __typeof(error_at_line) __error_at_line attribute_hidden;
75 void __error_at_line (int status, int errnum, const char *file_name,
76 unsigned int line_number, const char *message, ...)
80 if (error_one_per_line) {
81 static const char *old_file_name;
82 static unsigned int old_line_number;
84 if (old_line_number == line_number &&
85 (file_name == old_file_name || !strcmp (old_file_name, file_name)))
86 /* Simply return and print nothing. */
89 old_file_name = file_name;
90 old_line_number = line_number;
95 if (error_print_progname)
96 (*error_print_progname) ();
98 fprintf (stderr, "%s:", __uclibc_progname);
100 if (file_name != NULL)
101 fprintf (stderr, "%s:%d: ", file_name, line_number);
103 va_start (args, message);
104 vfprintf (stderr, message, args);
107 ++error_message_count;
109 fprintf (stderr, ": %s", strerror (errnum));
115 weak_alias(__error_at_line,error_at_line)