Mercurial > gnulib
annotate lib/error.c @ 40186:8964917f9574
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Mon, 18 Feb 2019 08:02:49 -0800 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
1268 | 1 /* Error handler for noninteractive utilities |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19595
diff
changeset
|
2 Copyright (C) 1990-1998, 2000-2007, 2009-2019 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 |
19190 | 16 along with this program. If not, see <https://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) |
18397
dbcfb44c9695
Port modules to use getprogname explicitly
Pino Toscano <ptoscano@redhat.com>
parents:
18189
diff
changeset
|
45 #else |
dbcfb44c9695
Port modules to use getprogname explicitly
Pino Toscano <ptoscano@redhat.com>
parents:
18189
diff
changeset
|
46 # include "getprogname.h" |
3446 | 47 #endif |
9 | 48 |
5319
61af141e6032
error.c, md5.c, regex.c: Use '#if USE_UNLOCKED_IO' instead of
Simon Josefsson <simon@josefsson.org>
parents:
5318
diff
changeset
|
49 #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
|
50 # 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
|
51 #endif |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
52 |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
53 #ifndef _ |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
54 # define _(String) String |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
55 #endif |
1268 | 56 |
398 | 57 /* If NULL, error will flush stdout, then print on stderr the program |
58 name, a colon and a space. Otherwise, error will call this | |
59 function without parameters instead. */ | |
4636 | 60 void (*error_print_progname) (void); |
572 | 61 |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16214
diff
changeset
|
62 /* This variable is incremented each time 'error' is called. */ |
572 | 63 unsigned int error_message_count; |
9 | 64 |
527 | 65 #ifdef _LIBC |
572 | 66 /* In the GNU C library, there is a predefined variable for this. */ |
67 | |
1289 | 68 # define program_name program_invocation_name |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
69 # include <errno.h> |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
70 # 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
|
71 # include <libio/libioP.h> |
572 | 72 |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16214
diff
changeset
|
73 /* In GNU libc we want do not want to use the common name 'error' directly. |
1268 | 74 Instead make it a weak alias. */ |
3446 | 75 extern void __error (int status, int errnum, const char *message, ...) |
76 __attribute__ ((__format__ (__printf__, 3, 4))); | |
77 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
|
78 unsigned int line_number, const char *message, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
79 ...) |
17750
7355c636029c
error: drop spurious semicolon
Eric Blake <eblake@redhat.com>
parents:
17719
diff
changeset
|
80 __attribute__ ((__format__ (__printf__, 5, 6))); |
1289 | 81 # define error __error |
82 # define error_at_line __error_at_line | |
1268 | 83 |
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 # include <libio/iolibio.h> |
17718
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17576
diff
changeset
|
85 # 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
|
86 # undef putc |
17718
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17576
diff
changeset
|
87 # 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
|
88 |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
89 # include <bits/libc-lock.h> |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
90 |
1289 | 91 #else /* not _LIBC */ |
527 | 92 |
11713
2b42a598bba2
error: avoid undefined use of stdout
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
93 # 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
|
94 # include <unistd.h> |
11713
2b42a598bba2
error: avoid undefined use of stdout
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
95 |
19595
beb2ad957aca
Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
96 # if defined _WIN32 && ! defined __CYGWIN__ |
16214
ec738d6aeef5
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
97 /* 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
|
98 # define WIN32_LEAN_AND_MEAN |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
99 # 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
|
100 /* Get _get_osfhandle. */ |
18883
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18827
diff
changeset
|
101 # if GNULIB_MSVC_NOTHROW |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18827
diff
changeset
|
102 # include "msvc-nothrow.h" |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18827
diff
changeset
|
103 # else |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18827
diff
changeset
|
104 # include <io.h> |
19886582ca8d
Implement a way to opt out from MSVC support.
Bruno Haible <bruno@clisp.org>
parents:
18827
diff
changeset
|
105 # endif |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
106 # endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
107 |
13326
9a066ce4a8a5
error: Use system's fcntl function.
Bruno Haible <bruno@clisp.org>
parents:
13324
diff
changeset
|
108 /* 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
|
109 # undef fcntl |
9a066ce4a8a5
error: Use system's fcntl function.
Bruno Haible <bruno@clisp.org>
parents:
13324
diff
changeset
|
110 |
18814
7388d5aaf0d5
Fix conflict between strerror_r-posix module and AC_FUNC_STRERROR_R.
Bruno Haible <bruno@clisp.org>
parents:
18793
diff
changeset
|
111 # if !(GNULIB_STRERROR_R_POSIX || HAVE_DECL_STRERROR_R) |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
112 # ifndef HAVE_DECL_STRERROR_R |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
113 "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
|
114 # endif |
14868 | 115 # if STRERROR_R_CHAR_P |
18793
ab5372ad42ea
error: Avoid "function declaration isn't a prototype" warning.
Tim Rühsen <tim.ruehsen@gmx.de>
parents:
18626
diff
changeset
|
116 char *strerror_r (int errnum, char *buf, size_t buflen); |
14868 | 117 # else |
18793
ab5372ad42ea
error: Avoid "function declaration isn't a prototype" warning.
Tim Rühsen <tim.ruehsen@gmx.de>
parents:
18626
diff
changeset
|
118 int strerror_r (int errnum, char *buf, size_t buflen); |
14868 | 119 # endif |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
120 # endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
121 |
18397
dbcfb44c9695
Port modules to use getprogname explicitly
Pino Toscano <ptoscano@redhat.com>
parents:
18189
diff
changeset
|
122 #define program_name getprogname () |
9 | 123 |
18814
7388d5aaf0d5
Fix conflict between strerror_r-posix module and AC_FUNC_STRERROR_R.
Bruno Haible <bruno@clisp.org>
parents:
18793
diff
changeset
|
124 # if GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r |
1289 | 125 # define __strerror_r strerror_r |
18814
7388d5aaf0d5
Fix conflict between strerror_r-posix module and AC_FUNC_STRERROR_R.
Bruno Haible <bruno@clisp.org>
parents:
18793
diff
changeset
|
126 # endif /* GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r */ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
127 #endif /* not _LIBC */ |
9 | 128 |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
129 #if !_LIBC |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
130 /* Return non-zero if FD is open. */ |
17186
84256646069c
error, filevercmp: no 'static inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16235
diff
changeset
|
131 static int |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
132 is_open (int fd) |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
133 { |
19595
beb2ad957aca
Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
134 # if defined _WIN32 && ! defined __CYGWIN__ |
16214
ec738d6aeef5
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
135 /* 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
|
136 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
|
137 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
|
138 F_GETFL. */ |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
139 return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE; |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
140 # else |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
141 # ifndef F_GETFL |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
142 # error Please port fcntl to your platform |
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 return 0 <= fcntl (fd, F_GETFL); |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
145 # endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
146 } |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
147 #endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
148 |
17186
84256646069c
error, filevercmp: no 'static inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16235
diff
changeset
|
149 static void |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
150 flush_stdout (void) |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
151 { |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
152 #if !_LIBC |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
153 int stdout_fd; |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
154 |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
155 # if GNULIB_FREOPEN_SAFER |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
156 /* 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
|
157 fileno (stdout) == 1 |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
158 whenever stdout is open. */ |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
159 stdout_fd = STDOUT_FILENO; |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
160 # else |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
161 /* 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
|
162 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
|
163 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
|
164 stdout_fd = fileno (stdout); |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
165 # endif |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
166 /* 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
|
167 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
|
168 is always defined, but too draconian. */ |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
169 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
|
170 #endif |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
171 fflush (stdout); |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
172 } |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
173 |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
174 static void |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
175 print_errno_message (int errnum) |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
176 { |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
177 char const *s; |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
178 |
18814
7388d5aaf0d5
Fix conflict between strerror_r-posix module and AC_FUNC_STRERROR_R.
Bruno Haible <bruno@clisp.org>
parents:
18793
diff
changeset
|
179 #if _LIBC || GNULIB_STRERROR_R_POSIX || defined HAVE_STRERROR_R |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
180 char errbuf[1024]; |
18827
d5b56023fff5
error: Fix mistake in 2017-04-23 commit.
Bruno Haible <bruno@clisp.org>
parents:
18814
diff
changeset
|
181 # if _LIBC || (!GNULIB_STRERROR_R_POSIX && STRERROR_R_CHAR_P) |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
182 s = __strerror_r (errnum, errbuf, sizeof errbuf); |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
183 # else |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
184 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
|
185 s = errbuf; |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
186 else |
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
187 s = 0; |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
188 # endif |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
189 #else |
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
190 s = strerror (errnum); |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
191 #endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
192 |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
193 #if !_LIBC |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
194 if (! s) |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
195 s = _("Unknown system error"); |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
196 #endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
197 |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
198 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
199 __fxprintf (NULL, ": %s", s); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
200 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
201 fprintf (stderr, ": %s", s); |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
202 #endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
203 } |
3446 | 204 |
17520
e4bb7b0088bb
error: add the printf attribute to a static function
Jim Meyering <meyering@fb.com>
parents:
17249
diff
changeset
|
205 static void _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) _GL_ARG_NONNULL ((3)) |
3446 | 206 error_tail (int status, int errnum, const char *message, va_list args) |
207 { | |
4695 | 208 #if _LIBC |
3446 | 209 if (_IO_fwide (stderr, 0) > 0) |
210 { | |
211 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
|
212 wchar_t *wmessage = NULL; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
213 mbstate_t st; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
214 size_t res; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
215 const char *tmp; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
216 bool use_malloc = false; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
217 |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
218 while (1) |
12421
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 (__libc_use_alloca (len * sizeof (wchar_t))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
221 wmessage = (wchar_t *) alloca (len * sizeof (wchar_t)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
222 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
223 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
224 if (!use_malloc) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
225 wmessage = NULL; |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
226 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
227 wchar_t *p = (wchar_t *) realloc (wmessage, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
228 len * sizeof (wchar_t)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
229 if (p == NULL) |
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 free (wmessage); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
232 fputws_unlocked (L"out of memory\n", stderr); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
233 return; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
234 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
235 wmessage = p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
236 use_malloc = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
237 } |
3446 | 238 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
239 memset (&st, '\0', sizeof (st)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
240 tmp = message; |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
241 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
242 res = mbsrtowcs (wmessage, &tmp, len, &st); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
243 if (res != len) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
244 break; |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
245 |
17718
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17576
diff
changeset
|
246 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
|
247 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
248 /* 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
|
249 res = (size_t) -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
250 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
251 } |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
252 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
253 len *= 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
254 } |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
255 |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
256 if (res == (size_t) -1) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
257 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
258 /* The string cannot be converted. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
259 if (use_malloc) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
260 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
261 free (wmessage); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
262 use_malloc = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
263 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
264 wmessage = (wchar_t *) L"???"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
265 } |
3446 | 266 |
267 __vfwprintf (stderr, wmessage, args); | |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
268 |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
269 if (use_malloc) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
270 free (wmessage); |
3446 | 271 } |
272 else | |
4695 | 273 #endif |
3446 | 274 vfprintf (stderr, message, args); |
275 | |
276 ++error_message_count; | |
277 if (errnum) | |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
278 print_errno_message (errnum); |
4680
0ec32cb1202f
Correct indentation of cpp directives.
Jim Meyering <jim@meyering.net>
parents:
4636
diff
changeset
|
279 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
280 __fxprintf (NULL, "\n"); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
281 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
282 putc ('\n', stderr); |
4680
0ec32cb1202f
Correct indentation of cpp directives.
Jim Meyering <jim@meyering.net>
parents:
4636
diff
changeset
|
283 #endif |
3446 | 284 fflush (stderr); |
285 if (status) | |
286 exit (status); | |
287 } | |
288 | |
289 | |
9 | 290 /* Print the program name and error message MESSAGE, which is a printf-style |
291 format string with optional args. | |
292 If ERRNUM is nonzero, print its corresponding system error message. | |
293 Exit with status STATUS if it is nonzero. */ | |
294 void | |
398 | 295 error (int status, int errnum, const char *message, ...) |
9 | 296 { |
297 va_list args; | |
298 | |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
299 #if defined _LIBC && defined __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
300 /* 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
|
301 cancellation. Therefore disable cancellation for now. */ |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
302 int state = PTHREAD_CANCEL_ENABLE; |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
303 __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
|
304 0); |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
305 #endif |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
306 |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
307 flush_stdout (); |
3446 | 308 #ifdef _LIBC |
309 _IO_flockfile (stderr); | |
310 #endif | |
398 | 311 if (error_print_progname) |
312 (*error_print_progname) (); | |
313 else | |
314 { | |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
315 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
316 __fxprintf (NULL, "%s: ", program_name); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
317 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
318 fprintf (stderr, "%s: ", program_name); |
3446 | 319 #endif |
398 | 320 } |
321 | |
4636 | 322 va_start (args, message); |
3446 | 323 error_tail (status, errnum, message, args); |
18947
b8292f52af02
error: fix POSIX violation for va_end
Paul Eggert <eggert@cs.ucla.edu>
parents:
18883
diff
changeset
|
324 va_end (args); |
3446 | 325 |
326 #ifdef _LIBC | |
327 _IO_funlockfile (stderr); | |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
328 # ifdef __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
329 __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
330 # endif |
3446 | 331 #endif |
9 | 332 } |
572 | 333 |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
334 /* 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
|
335 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
|
336 int error_one_per_line; |
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 void |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
339 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
|
340 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
|
341 { |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
342 va_list args; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
343 |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
344 if (error_one_per_line) |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
345 { |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
346 static const char *old_file_name; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
347 static unsigned int old_line_number; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
348 |
3446 | 349 if (old_line_number == line_number |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
350 && (file_name == old_file_name |
17718
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17576
diff
changeset
|
351 || (old_file_name != NULL |
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17576
diff
changeset
|
352 && file_name != NULL |
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17576
diff
changeset
|
353 && strcmp (old_file_name, file_name) == 0))) |
cc408fc7021c
Sync up error.c with glibc
Siddhesh Poyarekar <siddhesh@redhat.com>
parents:
17576
diff
changeset
|
354 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
355 /* Simply return and print nothing. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
356 return; |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
357 |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
358 old_file_name = file_name; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
359 old_line_number = line_number; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
360 } |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
361 |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
362 #if defined _LIBC && defined __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
363 /* 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
|
364 cancellation. Therefore disable cancellation for now. */ |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
365 int state = PTHREAD_CANCEL_ENABLE; |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
366 __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
|
367 0); |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
368 #endif |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
369 |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
370 flush_stdout (); |
3446 | 371 #ifdef _LIBC |
372 _IO_flockfile (stderr); | |
373 #endif | |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
374 if (error_print_progname) |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
375 (*error_print_progname) (); |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
376 else |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
377 { |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
378 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
379 __fxprintf (NULL, "%s:", program_name); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
380 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
381 fprintf (stderr, "%s:", program_name); |
3446 | 382 #endif |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
383 } |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
384 |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
385 #if _LIBC |
18027
870a2ccf6d6f
error.c: correct printf-style format: %d -> %u
Jim Meyering <meyering@fb.com>
parents:
17848
diff
changeset
|
386 __fxprintf (NULL, file_name != NULL ? "%s:%u: " : " ", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
387 file_name, line_number); |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
388 #else |
18027
870a2ccf6d6f
error.c: correct printf-style format: %d -> %u
Jim Meyering <meyering@fb.com>
parents:
17848
diff
changeset
|
389 fprintf (stderr, file_name != NULL ? "%s:%u: " : " ", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
390 file_name, line_number); |
3446 | 391 #endif |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
392 |
4636 | 393 va_start (args, message); |
3446 | 394 error_tail (status, errnum, message, args); |
18947
b8292f52af02
error: fix POSIX violation for va_end
Paul Eggert <eggert@cs.ucla.edu>
parents:
18883
diff
changeset
|
395 va_end (args); |
3446 | 396 |
397 #ifdef _LIBC | |
398 _IO_funlockfile (stderr); | |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
399 # ifdef __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
400 __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
401 # endif |
3446 | 402 #endif |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
403 } |
1268 | 404 |
405 #ifdef _LIBC | |
406 /* Make the weak alias. */ | |
1289 | 407 # undef error |
408 # undef error_at_line | |
1268 | 409 weak_alias (__error, error) |
410 weak_alias (__error_at_line, error_at_line) | |
411 #endif |