Mercurial > hg > octave-jordi > gnulib-hg
annotate lib/error.c @ 18070:d460ec17f09f
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Tue, 28 Jul 2015 13:57:32 -0700 |
parents | 870a2ccf6d6f |
children |
rev | line source |
---|---|
1268 | 1 /* Error handler for noninteractive utilities |
17848 | 2 Copyright (C) 1990-1998, 2000-2007, 2009-2015 Free Software Foundation, Inc. |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
3 This file is part of the GNU C Library. |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
4 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9112
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
4020 | 6 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9112
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9112
diff
changeset
|
8 (at your option) any later version. |
9 | 9 |
4020 | 10 This program is distributed in the hope that it will be useful, |
724
3f555c6de1b9
Use #if, not #ifdef in test for HAVE_CONFIG_H.
Jim Meyering <jim@meyering.net>
parents:
719
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
4020 | 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 GNU General Public License for more details. | |
572 | 14 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9112
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9112
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
9 | 17 |
398 | 18 /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */ |
19 | |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
7232
diff
changeset
|
20 #if !_LIBC |
1289 | 21 # include <config.h> |
398 | 22 #endif |
9 | 23 |
4636 | 24 #include "error.h" |
25 | |
26 #include <stdarg.h> | |
9 | 27 #include <stdio.h> |
4636 | 28 #include <stdlib.h> |
29 #include <string.h> | |
3966
22d3032f0239
Include gettext.h instead of <libintl.h> with #ifdefs.
Bruno Haible <bruno@clisp.org>
parents:
3618
diff
changeset
|
30 |
5562
2479d10c3961
[!_LIBC && !ENABLE_NLS]: Do not include "gettext.h";
Paul Eggert <eggert@cs.ucla.edu>
parents:
5319
diff
changeset
|
31 #if !_LIBC && ENABLE_NLS |
3966
22d3032f0239
Include gettext.h instead of <libintl.h> with #ifdefs.
Bruno Haible <bruno@clisp.org>
parents:
3618
diff
changeset
|
32 # include "gettext.h" |
9112
8b2acf250f22
Add missing definition of _ macro.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
33 # define _(msgid) gettext (msgid) |
2984
5b1fa2113060
Add a couple #includes, merging from GNU libc version.
Jim Meyering <jim@meyering.net>
parents:
2643
diff
changeset
|
34 #endif |
3966
22d3032f0239
Include gettext.h instead of <libintl.h> with #ifdefs.
Bruno Haible <bruno@clisp.org>
parents:
3618
diff
changeset
|
35 |
3446 | 36 #ifdef _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
37 # include <libintl.h> |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
38 # include <stdbool.h> |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
39 # include <stdint.h> |
3446 | 40 # include <wchar.h> |
41 # define mbsrtowcs __mbsrtowcs | |
17719
41c703805963
Define macros for glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17718
diff
changeset
|
42 # define USE_UNLOCKED_IO 0 |
41c703805963
Define macros for glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17718
diff
changeset
|
43 # define _GL_ATTRIBUTE_FORMAT_PRINTF(a, b) |
41c703805963
Define macros for glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17718
diff
changeset
|
44 # define _GL_ARG_NONNULL(a) |
3446 | 45 #endif |
9 | 46 |
5319
61af141e6032
error.c, md5.c, regex.c: Use '#if USE_UNLOCKED_IO' instead of
Simon Josefsson <simon@josefsson.org>
parents:
5318
diff
changeset
|
47 #if USE_UNLOCKED_IO |
4070
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
48 # include "unlocked-io.h" |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
49 #endif |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
50 |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
51 #ifndef _ |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
52 # define _(String) String |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
53 #endif |
1268 | 54 |
398 | 55 /* If NULL, error will flush stdout, then print on stderr the program |
56 name, a colon and a space. Otherwise, error will call this | |
57 function without parameters instead. */ | |
4636 | 58 void (*error_print_progname) (void); |
572 | 59 |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16214
diff
changeset
|
60 /* This variable is incremented each time 'error' is called. */ |
572 | 61 unsigned int error_message_count; |
9 | 62 |
527 | 63 #ifdef _LIBC |
572 | 64 /* In the GNU C library, there is a predefined variable for this. */ |
65 | |
1289 | 66 # define program_name program_invocation_name |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
67 # include <errno.h> |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
68 # include <limits.h> |
4070
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
69 # include <libio/libioP.h> |
572 | 70 |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16214
diff
changeset
|
71 /* In GNU libc we want do not want to use the common name 'error' directly. |
1268 | 72 Instead make it a weak alias. */ |
3446 | 73 extern void __error (int status, int errnum, const char *message, ...) |
74 __attribute__ ((__format__ (__printf__, 3, 4))); | |
75 extern void __error_at_line (int status, int errnum, const char *file_name, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
76 unsigned int line_number, const char *message, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
77 ...) |
17750
7355c636029c
error: drop spurious semicolon
Eric Blake <eblake@redhat.com>
parents:
17719
diff
changeset
|
78 __attribute__ ((__format__ (__printf__, 5, 6))); |
1289 | 79 # define error __error |
80 # define error_at_line __error_at_line | |
1268 | 81 |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
82 # include <libio/iolibio.h> |
17718
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17587
diff
changeset
|
83 # define fflush(s) _IO_fflush (s) |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
84 # undef putc |
17718
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17587
diff
changeset
|
85 # define putc(c, fp) _IO_putc (c, fp) |
2984
5b1fa2113060
Add a couple #includes, merging from GNU libc version.
Jim Meyering <jim@meyering.net>
parents:
2643
diff
changeset
|
86 |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
87 # include <bits/libc-lock.h> |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
88 |
1289 | 89 #else /* not _LIBC */ |
527 | 90 |
11713
2b42a598bba2
error: avoid undefined use of stdout
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
91 # include <fcntl.h> |
12338
6d35e757e103
Oops, move the include of unistd.h in the last commit.
Bruno Haible <bruno@clisp.org>
parents:
12337
diff
changeset
|
92 # include <unistd.h> |
11713
2b42a598bba2
error: avoid undefined use of stdout
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
93 |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
94 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
16214
ec738d6aeef5
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
95 /* Get declarations of the native Windows API functions. */ |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
96 # define WIN32_LEAN_AND_MEAN |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
97 # include <windows.h> |
15752
b86e9061a6d0
New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
14868
diff
changeset
|
98 /* Get _get_osfhandle. */ |
b86e9061a6d0
New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
14868
diff
changeset
|
99 # include "msvc-nothrow.h" |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
100 # endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
101 |
13326
9a066ce4a8a5
error: Use system's fcntl function.
Bruno Haible <bruno@clisp.org>
parents:
13324
diff
changeset
|
102 /* The gnulib override of fcntl is not needed in this file. */ |
9a066ce4a8a5
error: Use system's fcntl function.
Bruno Haible <bruno@clisp.org>
parents:
13324
diff
changeset
|
103 # undef fcntl |
9a066ce4a8a5
error: Use system's fcntl function.
Bruno Haible <bruno@clisp.org>
parents:
13324
diff
changeset
|
104 |
14868 | 105 # if !HAVE_DECL_STRERROR_R |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
106 # ifndef HAVE_DECL_STRERROR_R |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
107 "this configure-time declaration test was not run" |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
108 # endif |
14868 | 109 # if STRERROR_R_CHAR_P |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
110 char *strerror_r (); |
14868 | 111 # else |
112 int strerror_r (); | |
113 # endif | |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
114 # endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
115 |
398 | 116 /* The calling program should define program_name and set it to the |
117 name of the executing program. */ | |
118 extern char *program_name; | |
9 | 119 |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
120 # if HAVE_STRERROR_R || defined strerror_r |
1289 | 121 # define __strerror_r strerror_r |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
122 # endif /* HAVE_STRERROR_R || defined strerror_r */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
123 #endif /* not _LIBC */ |
9 | 124 |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
125 #if !_LIBC |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
126 /* Return non-zero if FD is open. */ |
17186
84256646069c
error, filevercmp: no 'static inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16235
diff
changeset
|
127 static int |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
128 is_open (int fd) |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
129 { |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
130 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
16214
ec738d6aeef5
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
131 /* On native Windows: The initial state of unassigned standard file |
ec738d6aeef5
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
132 descriptors is that they are open but point to an INVALID_HANDLE_VALUE. |
ec738d6aeef5
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
133 There is no fcntl, and the gnulib replacement fcntl does not support |
ec738d6aeef5
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
134 F_GETFL. */ |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
135 return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE; |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
136 # else |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
137 # ifndef F_GETFL |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
138 # error Please port fcntl to your platform |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
139 # endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
140 return 0 <= fcntl (fd, F_GETFL); |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
141 # endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
142 } |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
143 #endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
144 |
17186
84256646069c
error, filevercmp: no 'static inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16235
diff
changeset
|
145 static void |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
146 flush_stdout (void) |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
147 { |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
148 #if !_LIBC |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
149 int stdout_fd; |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
150 |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
151 # if GNULIB_FREOPEN_SAFER |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
152 /* Use of gnulib's freopen-safer module normally ensures that |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
153 fileno (stdout) == 1 |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
154 whenever stdout is open. */ |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
155 stdout_fd = STDOUT_FILENO; |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
156 # else |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
157 /* POSIX states that fileno (stdout) after fclose is unspecified. But in |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
158 practice it is not a problem, because stdout is statically allocated and |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
159 the fd of a FILE stream is stored as a field in its allocated memory. */ |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
160 stdout_fd = fileno (stdout); |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
161 # endif |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
162 /* POSIX states that fflush (stdout) after fclose is unspecified; it |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
163 is safe in glibc, but not on all other platforms. fflush (NULL) |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
164 is always defined, but too draconian. */ |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
165 if (0 <= stdout_fd && is_open (stdout_fd)) |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
166 #endif |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
167 fflush (stdout); |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
168 } |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
169 |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
170 static void |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
171 print_errno_message (int errnum) |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
172 { |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
173 char const *s; |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
174 |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
175 #if defined HAVE_STRERROR_R || _LIBC |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
176 char errbuf[1024]; |
17719
41c703805963
Define macros for glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17718
diff
changeset
|
177 # if _LIBC || STRERROR_R_CHAR_P |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
178 s = __strerror_r (errnum, errbuf, sizeof errbuf); |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
179 # else |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
180 if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0) |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
181 s = errbuf; |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
182 else |
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
183 s = 0; |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
184 # endif |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
185 #else |
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
186 s = strerror (errnum); |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
187 #endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
188 |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
189 #if !_LIBC |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
190 if (! s) |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
191 s = _("Unknown system error"); |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
192 #endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
193 |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
194 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
195 __fxprintf (NULL, ": %s", s); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
196 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
197 fprintf (stderr, ": %s", s); |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
198 #endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
199 } |
3446 | 200 |
17531
e4bb7b0088bb
error: add the printf attribute to a static function
Jim Meyering <meyering@fb.com>
parents:
17249
diff
changeset
|
201 static void _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) _GL_ARG_NONNULL ((3)) |
3446 | 202 error_tail (int status, int errnum, const char *message, va_list args) |
203 { | |
4695 | 204 #if _LIBC |
3446 | 205 if (_IO_fwide (stderr, 0) > 0) |
206 { | |
207 size_t len = strlen (message) + 1; | |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
208 wchar_t *wmessage = NULL; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
209 mbstate_t st; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
210 size_t res; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
211 const char *tmp; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
212 bool use_malloc = false; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
213 |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
214 while (1) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
215 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
216 if (__libc_use_alloca (len * sizeof (wchar_t))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
217 wmessage = (wchar_t *) alloca (len * sizeof (wchar_t)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
218 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
219 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
220 if (!use_malloc) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
221 wmessage = NULL; |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
222 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
223 wchar_t *p = (wchar_t *) realloc (wmessage, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
224 len * sizeof (wchar_t)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
225 if (p == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
226 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
227 free (wmessage); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
228 fputws_unlocked (L"out of memory\n", stderr); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
229 return; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
230 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
231 wmessage = p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
232 use_malloc = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
233 } |
3446 | 234 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
235 memset (&st, '\0', sizeof (st)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
236 tmp = message; |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
237 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
238 res = mbsrtowcs (wmessage, &tmp, len, &st); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
239 if (res != len) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
240 break; |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
241 |
17718
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17587
diff
changeset
|
242 if (__builtin_expect (len >= SIZE_MAX / sizeof (wchar_t) / 2, 0)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
243 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
244 /* This really should not happen if everything is fine. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
245 res = (size_t) -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
246 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
247 } |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
248 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
249 len *= 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
250 } |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
251 |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
252 if (res == (size_t) -1) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
253 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
254 /* The string cannot be converted. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
255 if (use_malloc) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
256 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
257 free (wmessage); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
258 use_malloc = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
259 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
260 wmessage = (wchar_t *) L"???"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
261 } |
3446 | 262 |
263 __vfwprintf (stderr, wmessage, args); | |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
264 |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
265 if (use_malloc) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
266 free (wmessage); |
3446 | 267 } |
268 else | |
4695 | 269 #endif |
3446 | 270 vfprintf (stderr, message, args); |
271 va_end (args); | |
272 | |
273 ++error_message_count; | |
274 if (errnum) | |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
275 print_errno_message (errnum); |
4680
0ec32cb1202f
Correct indentation of cpp directives.
Jim Meyering <jim@meyering.net>
parents:
4636
diff
changeset
|
276 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
277 __fxprintf (NULL, "\n"); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
278 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
279 putc ('\n', stderr); |
4680
0ec32cb1202f
Correct indentation of cpp directives.
Jim Meyering <jim@meyering.net>
parents:
4636
diff
changeset
|
280 #endif |
3446 | 281 fflush (stderr); |
282 if (status) | |
283 exit (status); | |
284 } | |
285 | |
286 | |
9 | 287 /* Print the program name and error message MESSAGE, which is a printf-style |
288 format string with optional args. | |
289 If ERRNUM is nonzero, print its corresponding system error message. | |
290 Exit with status STATUS if it is nonzero. */ | |
291 void | |
398 | 292 error (int status, int errnum, const char *message, ...) |
9 | 293 { |
294 va_list args; | |
295 | |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
296 #if defined _LIBC && defined __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
297 /* We do not want this call to be cut short by a thread |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
298 cancellation. Therefore disable cancellation for now. */ |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
299 int state = PTHREAD_CANCEL_ENABLE; |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
300 __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
301 0); |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
302 #endif |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
303 |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
304 flush_stdout (); |
3446 | 305 #ifdef _LIBC |
306 _IO_flockfile (stderr); | |
307 #endif | |
398 | 308 if (error_print_progname) |
309 (*error_print_progname) (); | |
310 else | |
311 { | |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
312 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
313 __fxprintf (NULL, "%s: ", program_name); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
314 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
315 fprintf (stderr, "%s: ", program_name); |
3446 | 316 #endif |
398 | 317 } |
318 | |
4636 | 319 va_start (args, message); |
3446 | 320 error_tail (status, errnum, message, args); |
321 | |
322 #ifdef _LIBC | |
323 _IO_funlockfile (stderr); | |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
324 # ifdef __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
325 __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
326 # endif |
3446 | 327 #endif |
9 | 328 } |
572 | 329 |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
330 /* Sometimes we want to have at most one error per line. This |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
331 variable controls whether this mode is selected or not. */ |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
332 int error_one_per_line; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
333 |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
334 void |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
335 error_at_line (int status, int errnum, const char *file_name, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
336 unsigned int line_number, const char *message, ...) |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
337 { |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
338 va_list args; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
339 |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
340 if (error_one_per_line) |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
341 { |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
342 static const char *old_file_name; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
343 static unsigned int old_line_number; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
344 |
3446 | 345 if (old_line_number == line_number |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
346 && (file_name == old_file_name |
17718
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17587
diff
changeset
|
347 || (old_file_name != NULL |
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17587
diff
changeset
|
348 && file_name != NULL |
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17587
diff
changeset
|
349 && strcmp (old_file_name, file_name) == 0))) |
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17587
diff
changeset
|
350 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
351 /* Simply return and print nothing. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
352 return; |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
353 |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
354 old_file_name = file_name; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
355 old_line_number = line_number; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
356 } |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
357 |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
358 #if defined _LIBC && defined __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
359 /* We do not want this call to be cut short by a thread |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
360 cancellation. Therefore disable cancellation for now. */ |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
361 int state = PTHREAD_CANCEL_ENABLE; |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
362 __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
363 0); |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
364 #endif |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
365 |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
366 flush_stdout (); |
3446 | 367 #ifdef _LIBC |
368 _IO_flockfile (stderr); | |
369 #endif | |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
370 if (error_print_progname) |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
371 (*error_print_progname) (); |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
372 else |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
373 { |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
374 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
375 __fxprintf (NULL, "%s:", program_name); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
376 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
377 fprintf (stderr, "%s:", program_name); |
3446 | 378 #endif |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
379 } |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
380 |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
381 #if _LIBC |
18027
870a2ccf6d6f
error.c: correct printf-style format: %d -> %u
Jim Meyering <meyering@fb.com>
parents:
17848
diff
changeset
|
382 __fxprintf (NULL, file_name != NULL ? "%s:%u: " : " ", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
383 file_name, line_number); |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
384 #else |
18027
870a2ccf6d6f
error.c: correct printf-style format: %d -> %u
Jim Meyering <meyering@fb.com>
parents:
17848
diff
changeset
|
385 fprintf (stderr, file_name != NULL ? "%s:%u: " : " ", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
386 file_name, line_number); |
3446 | 387 #endif |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
388 |
4636 | 389 va_start (args, message); |
3446 | 390 error_tail (status, errnum, message, args); |
391 | |
392 #ifdef _LIBC | |
393 _IO_funlockfile (stderr); | |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
394 # ifdef __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
395 __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
396 # endif |
3446 | 397 #endif |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
398 } |
1268 | 399 |
400 #ifdef _LIBC | |
401 /* Make the weak alias. */ | |
1289 | 402 # undef error |
403 # undef error_at_line | |
1268 | 404 weak_alias (__error, error) |
405 weak_alias (__error_at_line, error_at_line) | |
406 #endif |