OSDN Git Service

Last portion of libc_hidden_proto removal.
[uclinux-h8/uClibc.git] / libc / misc / error / error.c
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.
4
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.
9
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.
14
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
18    02111-1307 USA.  */
19
20 /* Written by David MacKenzie <djm@gnu.ai.mit.edu>.  */
21 /* Adjusted slightly by Erik Andersen <andersen@uclibc.org> */
22
23 #include <stdio.h>
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <error.h>
28
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) */
38
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;
48
49 extern __typeof(error) __error attribute_hidden;
50 void __error (int status, int errnum, const char *message, ...)
51 {
52     va_list args;
53
54     fflush (stdout);
55
56     if (error_print_progname)
57         (*error_print_progname) ();
58     else
59         fprintf (stderr, "%s: ", __uclibc_progname);
60
61     va_start (args, message);
62     vfprintf (stderr, message, args);
63     va_end (args);
64     ++error_message_count;
65     if (errnum) {
66         fprintf (stderr, ": %s", strerror (errnum));
67     }
68     putc ('\n', stderr);
69     if (status)
70         exit (status);
71 }
72 weak_alias(__error,error)
73
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, ...)
77 {
78     va_list args;
79
80     if (error_one_per_line) {
81         static const char *old_file_name;
82         static unsigned int old_line_number;
83
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.  */
87             return;
88
89         old_file_name = file_name;
90         old_line_number = line_number;
91     }
92
93     fflush (stdout);
94
95     if (error_print_progname)
96         (*error_print_progname) ();
97     else
98         fprintf (stderr, "%s:", __uclibc_progname);
99
100     if (file_name != NULL)
101         fprintf (stderr, "%s:%d: ", file_name, line_number);
102
103     va_start (args, message);
104     vfprintf (stderr, message, args);
105     va_end (args);
106
107     ++error_message_count;
108     if (errnum) {
109         fprintf (stderr, ": %s", strerror (errnum));
110     }
111     putc ('\n', stderr);
112     if (status)
113         exit (status);
114 }
115 weak_alias(__error_at_line,error_at_line)