annotate lib/error.c @ 276:23034db7dd8a 2.5

fixed expression 'slots' to not store null on a pass 1 store
author lost
date Mon, 31 Aug 2009 08:39:36 +0000
parents d5392bb5da3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
272
d5392bb5da3c Added generated files
lost
parents:
diff changeset
1 /* Error handler for noninteractive utilities
d5392bb5da3c Added generated files
lost
parents:
diff changeset
2 Copyright (C) 1990-1998, 2000-2007 Free Software Foundation, Inc.
d5392bb5da3c Added generated files
lost
parents:
diff changeset
3 This file is part of the GNU C Library.
d5392bb5da3c Added generated files
lost
parents:
diff changeset
4
d5392bb5da3c Added generated files
lost
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
d5392bb5da3c Added generated files
lost
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
d5392bb5da3c Added generated files
lost
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
d5392bb5da3c Added generated files
lost
parents:
diff changeset
8 (at your option) any later version.
d5392bb5da3c Added generated files
lost
parents:
diff changeset
9
d5392bb5da3c Added generated files
lost
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
d5392bb5da3c Added generated files
lost
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
d5392bb5da3c Added generated files
lost
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d5392bb5da3c Added generated files
lost
parents:
diff changeset
13 GNU General Public License for more details.
d5392bb5da3c Added generated files
lost
parents:
diff changeset
14
d5392bb5da3c Added generated files
lost
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
d5392bb5da3c Added generated files
lost
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
17
d5392bb5da3c Added generated files
lost
parents:
diff changeset
18 /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
19
d5392bb5da3c Added generated files
lost
parents:
diff changeset
20 #if !_LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
21 # include <config.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
22 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
23
d5392bb5da3c Added generated files
lost
parents:
diff changeset
24 #include "error.h"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
25
d5392bb5da3c Added generated files
lost
parents:
diff changeset
26 #include <stdarg.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
27 #include <stdio.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
28 #include <stdlib.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
29 #include <string.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
30
d5392bb5da3c Added generated files
lost
parents:
diff changeset
31 #if !_LIBC && ENABLE_NLS
d5392bb5da3c Added generated files
lost
parents:
diff changeset
32 # include "gettext.h"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
33 # define _(msgid) gettext (msgid)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
34 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
35
d5392bb5da3c Added generated files
lost
parents:
diff changeset
36 #ifdef _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
37 # include <libintl.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
38 # include <stdbool.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
39 # include <stdint.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
40 # include <wchar.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
41 # define mbsrtowcs __mbsrtowcs
d5392bb5da3c Added generated files
lost
parents:
diff changeset
42 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
43
d5392bb5da3c Added generated files
lost
parents:
diff changeset
44 #if USE_UNLOCKED_IO
d5392bb5da3c Added generated files
lost
parents:
diff changeset
45 # include "unlocked-io.h"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
46 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
47
d5392bb5da3c Added generated files
lost
parents:
diff changeset
48 #ifndef _
d5392bb5da3c Added generated files
lost
parents:
diff changeset
49 # define _(String) String
d5392bb5da3c Added generated files
lost
parents:
diff changeset
50 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
51
d5392bb5da3c Added generated files
lost
parents:
diff changeset
52 /* If NULL, error will flush stdout, then print on stderr the program
d5392bb5da3c Added generated files
lost
parents:
diff changeset
53 name, a colon and a space. Otherwise, error will call this
d5392bb5da3c Added generated files
lost
parents:
diff changeset
54 function without parameters instead. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
55 void (*error_print_progname) (void);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
56
d5392bb5da3c Added generated files
lost
parents:
diff changeset
57 /* This variable is incremented each time `error' is called. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
58 unsigned int error_message_count;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
59
d5392bb5da3c Added generated files
lost
parents:
diff changeset
60 #ifdef _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
61 /* In the GNU C library, there is a predefined variable for this. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
62
d5392bb5da3c Added generated files
lost
parents:
diff changeset
63 # define program_name program_invocation_name
d5392bb5da3c Added generated files
lost
parents:
diff changeset
64 # include <errno.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
65 # include <limits.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
66 # include <libio/libioP.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
67
d5392bb5da3c Added generated files
lost
parents:
diff changeset
68 /* In GNU libc we want do not want to use the common name `error' directly.
d5392bb5da3c Added generated files
lost
parents:
diff changeset
69 Instead make it a weak alias. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
70 extern void __error (int status, int errnum, const char *message, ...)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
71 __attribute__ ((__format__ (__printf__, 3, 4)));
d5392bb5da3c Added generated files
lost
parents:
diff changeset
72 extern void __error_at_line (int status, int errnum, const char *file_name,
d5392bb5da3c Added generated files
lost
parents:
diff changeset
73 unsigned int line_number, const char *message,
d5392bb5da3c Added generated files
lost
parents:
diff changeset
74 ...)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
75 __attribute__ ((__format__ (__printf__, 5, 6)));;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
76 # define error __error
d5392bb5da3c Added generated files
lost
parents:
diff changeset
77 # define error_at_line __error_at_line
d5392bb5da3c Added generated files
lost
parents:
diff changeset
78
d5392bb5da3c Added generated files
lost
parents:
diff changeset
79 # include <libio/iolibio.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
80 # define fflush(s) INTUSE(_IO_fflush) (s)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
81 # undef putc
d5392bb5da3c Added generated files
lost
parents:
diff changeset
82 # define putc(c, fp) INTUSE(_IO_putc) (c, fp)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
83
d5392bb5da3c Added generated files
lost
parents:
diff changeset
84 # include <bits/libc-lock.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
85
d5392bb5da3c Added generated files
lost
parents:
diff changeset
86 #else /* not _LIBC */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
87
d5392bb5da3c Added generated files
lost
parents:
diff changeset
88 # if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
d5392bb5da3c Added generated files
lost
parents:
diff changeset
89 # ifndef HAVE_DECL_STRERROR_R
d5392bb5da3c Added generated files
lost
parents:
diff changeset
90 "this configure-time declaration test was not run"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
91 # endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
92 char *strerror_r ();
d5392bb5da3c Added generated files
lost
parents:
diff changeset
93 # endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
94
d5392bb5da3c Added generated files
lost
parents:
diff changeset
95 /* The calling program should define program_name and set it to the
d5392bb5da3c Added generated files
lost
parents:
diff changeset
96 name of the executing program. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
97 extern char *program_name;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
98
d5392bb5da3c Added generated files
lost
parents:
diff changeset
99 # if HAVE_STRERROR_R || defined strerror_r
d5392bb5da3c Added generated files
lost
parents:
diff changeset
100 # define __strerror_r strerror_r
d5392bb5da3c Added generated files
lost
parents:
diff changeset
101 # endif /* HAVE_STRERROR_R || defined strerror_r */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
102 #endif /* not _LIBC */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
103
d5392bb5da3c Added generated files
lost
parents:
diff changeset
104 static void
d5392bb5da3c Added generated files
lost
parents:
diff changeset
105 print_errno_message (int errnum)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
106 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
107 char const *s;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
108
d5392bb5da3c Added generated files
lost
parents:
diff changeset
109 #if defined HAVE_STRERROR_R || _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
110 char errbuf[1024];
d5392bb5da3c Added generated files
lost
parents:
diff changeset
111 # if STRERROR_R_CHAR_P || _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
112 s = __strerror_r (errnum, errbuf, sizeof errbuf);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
113 # else
d5392bb5da3c Added generated files
lost
parents:
diff changeset
114 if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
115 s = errbuf;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
116 else
d5392bb5da3c Added generated files
lost
parents:
diff changeset
117 s = 0;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
118 # endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
119 #else
d5392bb5da3c Added generated files
lost
parents:
diff changeset
120 s = strerror (errnum);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
121 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
122
d5392bb5da3c Added generated files
lost
parents:
diff changeset
123 #if !_LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
124 if (! s)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
125 s = _("Unknown system error");
d5392bb5da3c Added generated files
lost
parents:
diff changeset
126 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
127
d5392bb5da3c Added generated files
lost
parents:
diff changeset
128 #if _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
129 __fxprintf (NULL, ": %s", s);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
130 #else
d5392bb5da3c Added generated files
lost
parents:
diff changeset
131 fprintf (stderr, ": %s", s);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
132 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
133 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
134
d5392bb5da3c Added generated files
lost
parents:
diff changeset
135 static void
d5392bb5da3c Added generated files
lost
parents:
diff changeset
136 error_tail (int status, int errnum, const char *message, va_list args)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
137 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
138 #if _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
139 if (_IO_fwide (stderr, 0) > 0)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
140 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
141 # define ALLOCA_LIMIT 2000
d5392bb5da3c Added generated files
lost
parents:
diff changeset
142 size_t len = strlen (message) + 1;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
143 wchar_t *wmessage = NULL;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
144 mbstate_t st;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
145 size_t res;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
146 const char *tmp;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
147 bool use_malloc = false;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
148
d5392bb5da3c Added generated files
lost
parents:
diff changeset
149 while (1)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
150 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
151 if (__libc_use_alloca (len * sizeof (wchar_t)))
d5392bb5da3c Added generated files
lost
parents:
diff changeset
152 wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
d5392bb5da3c Added generated files
lost
parents:
diff changeset
153 else
d5392bb5da3c Added generated files
lost
parents:
diff changeset
154 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
155 if (!use_malloc)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
156 wmessage = NULL;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
157
d5392bb5da3c Added generated files
lost
parents:
diff changeset
158 wchar_t *p = (wchar_t *) realloc (wmessage,
d5392bb5da3c Added generated files
lost
parents:
diff changeset
159 len * sizeof (wchar_t));
d5392bb5da3c Added generated files
lost
parents:
diff changeset
160 if (p == NULL)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
161 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
162 free (wmessage);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
163 fputws_unlocked (L"out of memory\n", stderr);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
164 return;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
165 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
166 wmessage = p;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
167 use_malloc = true;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
168 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
169
d5392bb5da3c Added generated files
lost
parents:
diff changeset
170 memset (&st, '\0', sizeof (st));
d5392bb5da3c Added generated files
lost
parents:
diff changeset
171 tmp = message;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
172
d5392bb5da3c Added generated files
lost
parents:
diff changeset
173 res = mbsrtowcs (wmessage, &tmp, len, &st);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
174 if (res != len)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
175 break;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
176
d5392bb5da3c Added generated files
lost
parents:
diff changeset
177 if (__builtin_expect (len >= SIZE_MAX / 2, 0))
d5392bb5da3c Added generated files
lost
parents:
diff changeset
178 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
179 /* This really should not happen if everything is fine. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
180 res = (size_t) -1;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
181 break;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
182 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
183
d5392bb5da3c Added generated files
lost
parents:
diff changeset
184 len *= 2;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
185 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
186
d5392bb5da3c Added generated files
lost
parents:
diff changeset
187 if (res == (size_t) -1)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
188 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
189 /* The string cannot be converted. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
190 if (use_malloc)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
191 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
192 free (wmessage);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
193 use_malloc = false;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
194 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
195 wmessage = (wchar_t *) L"???";
d5392bb5da3c Added generated files
lost
parents:
diff changeset
196 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
197
d5392bb5da3c Added generated files
lost
parents:
diff changeset
198 __vfwprintf (stderr, wmessage, args);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
199
d5392bb5da3c Added generated files
lost
parents:
diff changeset
200 if (use_malloc)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
201 free (wmessage);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
202 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
203 else
d5392bb5da3c Added generated files
lost
parents:
diff changeset
204 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
205 vfprintf (stderr, message, args);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
206 va_end (args);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
207
d5392bb5da3c Added generated files
lost
parents:
diff changeset
208 ++error_message_count;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
209 if (errnum)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
210 print_errno_message (errnum);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
211 #if _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
212 __fxprintf (NULL, "\n");
d5392bb5da3c Added generated files
lost
parents:
diff changeset
213 #else
d5392bb5da3c Added generated files
lost
parents:
diff changeset
214 putc ('\n', stderr);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
215 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
216 fflush (stderr);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
217 if (status)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
218 exit (status);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
219 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
220
d5392bb5da3c Added generated files
lost
parents:
diff changeset
221
d5392bb5da3c Added generated files
lost
parents:
diff changeset
222 /* Print the program name and error message MESSAGE, which is a printf-style
d5392bb5da3c Added generated files
lost
parents:
diff changeset
223 format string with optional args.
d5392bb5da3c Added generated files
lost
parents:
diff changeset
224 If ERRNUM is nonzero, print its corresponding system error message.
d5392bb5da3c Added generated files
lost
parents:
diff changeset
225 Exit with status STATUS if it is nonzero. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
226 void
d5392bb5da3c Added generated files
lost
parents:
diff changeset
227 error (int status, int errnum, const char *message, ...)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
228 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
229 va_list args;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
230
d5392bb5da3c Added generated files
lost
parents:
diff changeset
231 #if defined _LIBC && defined __libc_ptf_call
d5392bb5da3c Added generated files
lost
parents:
diff changeset
232 /* We do not want this call to be cut short by a thread
d5392bb5da3c Added generated files
lost
parents:
diff changeset
233 cancellation. Therefore disable cancellation for now. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
234 int state = PTHREAD_CANCEL_ENABLE;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
235 __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
d5392bb5da3c Added generated files
lost
parents:
diff changeset
236 0);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
237 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
238
d5392bb5da3c Added generated files
lost
parents:
diff changeset
239 fflush (stdout);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
240 #ifdef _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
241 _IO_flockfile (stderr);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
242 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
243 if (error_print_progname)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
244 (*error_print_progname) ();
d5392bb5da3c Added generated files
lost
parents:
diff changeset
245 else
d5392bb5da3c Added generated files
lost
parents:
diff changeset
246 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
247 #if _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
248 __fxprintf (NULL, "%s: ", program_name);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
249 #else
d5392bb5da3c Added generated files
lost
parents:
diff changeset
250 fprintf (stderr, "%s: ", program_name);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
251 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
252 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
253
d5392bb5da3c Added generated files
lost
parents:
diff changeset
254 va_start (args, message);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
255 error_tail (status, errnum, message, args);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
256
d5392bb5da3c Added generated files
lost
parents:
diff changeset
257 #ifdef _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
258 _IO_funlockfile (stderr);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
259 # ifdef __libc_ptf_call
d5392bb5da3c Added generated files
lost
parents:
diff changeset
260 __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
261 # endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
262 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
263 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
264
d5392bb5da3c Added generated files
lost
parents:
diff changeset
265 /* Sometimes we want to have at most one error per line. This
d5392bb5da3c Added generated files
lost
parents:
diff changeset
266 variable controls whether this mode is selected or not. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
267 int error_one_per_line;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
268
d5392bb5da3c Added generated files
lost
parents:
diff changeset
269 void
d5392bb5da3c Added generated files
lost
parents:
diff changeset
270 error_at_line (int status, int errnum, const char *file_name,
d5392bb5da3c Added generated files
lost
parents:
diff changeset
271 unsigned int line_number, const char *message, ...)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
272 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
273 va_list args;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
274
d5392bb5da3c Added generated files
lost
parents:
diff changeset
275 if (error_one_per_line)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
276 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
277 static const char *old_file_name;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
278 static unsigned int old_line_number;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
279
d5392bb5da3c Added generated files
lost
parents:
diff changeset
280 if (old_line_number == line_number
d5392bb5da3c Added generated files
lost
parents:
diff changeset
281 && (file_name == old_file_name
d5392bb5da3c Added generated files
lost
parents:
diff changeset
282 || strcmp (old_file_name, file_name) == 0))
d5392bb5da3c Added generated files
lost
parents:
diff changeset
283 /* Simply return and print nothing. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
284 return;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
285
d5392bb5da3c Added generated files
lost
parents:
diff changeset
286 old_file_name = file_name;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
287 old_line_number = line_number;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
288 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
289
d5392bb5da3c Added generated files
lost
parents:
diff changeset
290 #if defined _LIBC && defined __libc_ptf_call
d5392bb5da3c Added generated files
lost
parents:
diff changeset
291 /* We do not want this call to be cut short by a thread
d5392bb5da3c Added generated files
lost
parents:
diff changeset
292 cancellation. Therefore disable cancellation for now. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
293 int state = PTHREAD_CANCEL_ENABLE;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
294 __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
d5392bb5da3c Added generated files
lost
parents:
diff changeset
295 0);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
296 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
297
d5392bb5da3c Added generated files
lost
parents:
diff changeset
298 fflush (stdout);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
299 #ifdef _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
300 _IO_flockfile (stderr);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
301 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
302 if (error_print_progname)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
303 (*error_print_progname) ();
d5392bb5da3c Added generated files
lost
parents:
diff changeset
304 else
d5392bb5da3c Added generated files
lost
parents:
diff changeset
305 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
306 #if _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
307 __fxprintf (NULL, "%s:", program_name);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
308 #else
d5392bb5da3c Added generated files
lost
parents:
diff changeset
309 fprintf (stderr, "%s:", program_name);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
310 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
311 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
312
d5392bb5da3c Added generated files
lost
parents:
diff changeset
313 #if _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
314 __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ",
d5392bb5da3c Added generated files
lost
parents:
diff changeset
315 file_name, line_number);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
316 #else
d5392bb5da3c Added generated files
lost
parents:
diff changeset
317 fprintf (stderr, file_name != NULL ? "%s:%d: " : " ",
d5392bb5da3c Added generated files
lost
parents:
diff changeset
318 file_name, line_number);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
319 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
320
d5392bb5da3c Added generated files
lost
parents:
diff changeset
321 va_start (args, message);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
322 error_tail (status, errnum, message, args);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
323
d5392bb5da3c Added generated files
lost
parents:
diff changeset
324 #ifdef _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
325 _IO_funlockfile (stderr);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
326 # ifdef __libc_ptf_call
d5392bb5da3c Added generated files
lost
parents:
diff changeset
327 __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
328 # endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
329 #endif
d5392bb5da3c Added generated files
lost
parents:
diff changeset
330 }
d5392bb5da3c Added generated files
lost
parents:
diff changeset
331
d5392bb5da3c Added generated files
lost
parents:
diff changeset
332 #ifdef _LIBC
d5392bb5da3c Added generated files
lost
parents:
diff changeset
333 /* Make the weak alias. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
334 # undef error
d5392bb5da3c Added generated files
lost
parents:
diff changeset
335 # undef error_at_line
d5392bb5da3c Added generated files
lost
parents:
diff changeset
336 weak_alias (__error, error)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
337 weak_alias (__error_at_line, error_at_line)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
338 #endif