Mercurial > hg > octave-jordi > gnulib-hg
annotate lib/error.c @ 13326:9a066ce4a8a5
error: Use system's fcntl function.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 09 May 2010 12:16:00 +0200 |
parents | 2792eeac632f |
children | 97fc9a21a8fb |
rev | line source |
---|---|
1268 | 1 /* Error handler for noninteractive utilities |
12559
c2cbabec01dd
update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents:
12421
diff
changeset
|
2 Copyright (C) 1990-1998, 2000-2007, 2009-2010 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 | |
42 #endif | |
9 | 43 |
5319
61af141e6032
error.c, md5.c, regex.c: Use '#if USE_UNLOCKED_IO' instead of
Simon Josefsson <simon@josefsson.org>
parents:
5318
diff
changeset
|
44 #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
|
45 # 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
|
46 #endif |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
47 |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
48 #ifndef _ |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
49 # define _(String) String |
925594d77a99
Merge in changes from libc's misc/error.c, in preparation
Jim Meyering <jim@meyering.net>
parents:
4020
diff
changeset
|
50 #endif |
1268 | 51 |
398 | 52 /* If NULL, error will flush stdout, then print on stderr the program |
53 name, a colon and a space. Otherwise, error will call this | |
54 function without parameters instead. */ | |
4636 | 55 void (*error_print_progname) (void); |
572 | 56 |
57 /* This variable is incremented each time `error' is called. */ | |
58 unsigned int error_message_count; | |
9 | 59 |
527 | 60 #ifdef _LIBC |
572 | 61 /* In the GNU C library, there is a predefined variable for this. */ |
62 | |
1289 | 63 # define program_name program_invocation_name |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
64 # include <errno.h> |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
65 # 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
|
66 # include <libio/libioP.h> |
572 | 67 |
1268 | 68 /* In GNU libc we want do not want to use the common name `error' directly. |
69 Instead make it a weak alias. */ | |
3446 | 70 extern void __error (int status, int errnum, const char *message, ...) |
71 __attribute__ ((__format__ (__printf__, 3, 4))); | |
72 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
|
73 unsigned int line_number, const char *message, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
74 ...) |
3446 | 75 __attribute__ ((__format__ (__printf__, 5, 6)));; |
1289 | 76 # define error __error |
77 # define error_at_line __error_at_line | |
1268 | 78 |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
79 # include <libio/iolibio.h> |
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
80 # define fflush(s) INTUSE(_IO_fflush) (s) |
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
81 # undef putc |
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
82 # define putc(c, fp) INTUSE(_IO_putc) (c, fp) |
2984
5b1fa2113060
Add a couple #includes, merging from GNU libc version.
Jim Meyering <jim@meyering.net>
parents:
2643
diff
changeset
|
83 |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
84 # include <bits/libc-lock.h> |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
85 |
1289 | 86 #else /* not _LIBC */ |
527 | 87 |
11713
2b42a598bba2
error: avoid undefined use of stdout
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
88 # 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
|
89 # include <unistd.h> |
11713
2b42a598bba2
error: avoid undefined use of stdout
Eric Blake <ebb9@byu.net>
parents:
9309
diff
changeset
|
90 |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
91 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
92 /* Get declarations of the Win32 API functions. */ |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
93 # define WIN32_LEAN_AND_MEAN |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
94 # include <windows.h> |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
95 # endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
96 |
13326
9a066ce4a8a5
error: Use system's fcntl function.
Bruno Haible <bruno@clisp.org>
parents:
13324
diff
changeset
|
97 /* 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
|
98 # undef fcntl |
9a066ce4a8a5
error: Use system's fcntl function.
Bruno Haible <bruno@clisp.org>
parents:
13324
diff
changeset
|
99 |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
100 # if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
101 # ifndef HAVE_DECL_STRERROR_R |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
102 "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
|
103 # endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
104 char *strerror_r (); |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
105 # endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
106 |
398 | 107 /* The calling program should define program_name and set it to the |
108 name of the executing program. */ | |
109 extern char *program_name; | |
9 | 110 |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
111 # if HAVE_STRERROR_R || defined strerror_r |
1289 | 112 # define __strerror_r strerror_r |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
113 # endif /* HAVE_STRERROR_R || defined strerror_r */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
114 #endif /* not _LIBC */ |
9 | 115 |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
116 #if !_LIBC |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
117 /* Return non-zero if FD is open. */ |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
118 static inline int |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
119 is_open (int fd) |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
120 { |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
121 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
122 /* On Win32: The initial state of unassigned standard file descriptors is |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
123 that they are open but point to an INVALID_HANDLE_VALUE. There is no |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
124 fcntl, and the gnulib replacement fcntl does not support F_GETFL. */ |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
125 return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE; |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
126 # else |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
127 # ifndef F_GETFL |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
128 # error Please port fcntl to your platform |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
129 # endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
130 return 0 <= fcntl (fd, F_GETFL); |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
131 # endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
132 } |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
133 #endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
134 |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
135 static inline void |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
136 flush_stdout (void) |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
137 { |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
138 #if !_LIBC |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
139 int stdout_fd; |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
140 |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
141 # if GNULIB_FREOPEN_SAFER |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
142 /* 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
|
143 fileno (stdout) == 1 |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
144 whenever stdout is open. */ |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
145 stdout_fd = STDOUT_FILENO; |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
146 # else |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
147 /* 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
|
148 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
|
149 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
|
150 stdout_fd = fileno (stdout); |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
151 # endif |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
152 /* 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
|
153 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
|
154 is always defined, but too draconian. */ |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
155 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
|
156 #endif |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
157 fflush (stdout); |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
158 } |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
159 |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
160 static void |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
161 print_errno_message (int errnum) |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
162 { |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
163 char const *s; |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
164 |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
165 #if defined HAVE_STRERROR_R || _LIBC |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
166 char errbuf[1024]; |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
167 # if STRERROR_R_CHAR_P || _LIBC |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
168 s = __strerror_r (errnum, errbuf, sizeof errbuf); |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
169 # else |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
170 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
|
171 s = errbuf; |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
172 else |
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
173 s = 0; |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
174 # endif |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
175 #else |
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
176 s = strerror (errnum); |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
177 #endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
178 |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
179 #if !_LIBC |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
180 if (! s) |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
181 s = _("Unknown system error"); |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
182 #endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
183 |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
184 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
185 __fxprintf (NULL, ": %s", s); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
186 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
187 fprintf (stderr, ": %s", s); |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
188 #endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
189 } |
3446 | 190 |
191 static void | |
192 error_tail (int status, int errnum, const char *message, va_list args) | |
193 { | |
4695 | 194 #if _LIBC |
3446 | 195 if (_IO_fwide (stderr, 0) > 0) |
196 { | |
4695 | 197 # define ALLOCA_LIMIT 2000 |
3446 | 198 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
|
199 wchar_t *wmessage = NULL; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
200 mbstate_t st; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
201 size_t res; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
202 const char *tmp; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
203 bool use_malloc = false; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
204 |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
205 while (1) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
206 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
207 if (__libc_use_alloca (len * sizeof (wchar_t))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
208 wmessage = (wchar_t *) alloca (len * sizeof (wchar_t)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
209 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
210 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
211 if (!use_malloc) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
212 wmessage = NULL; |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
213 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
214 wchar_t *p = (wchar_t *) realloc (wmessage, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
215 len * sizeof (wchar_t)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
216 if (p == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
217 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
218 free (wmessage); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
219 fputws_unlocked (L"out of memory\n", stderr); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
220 return; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
221 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
222 wmessage = p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
223 use_malloc = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
224 } |
3446 | 225 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
226 memset (&st, '\0', sizeof (st)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
227 tmp = message; |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
228 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
229 res = mbsrtowcs (wmessage, &tmp, len, &st); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
230 if (res != len) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
231 break; |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
232 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
233 if (__builtin_expect (len >= SIZE_MAX / 2, 0)) |
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 /* 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
|
236 res = (size_t) -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
237 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
238 } |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
239 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
240 len *= 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
241 } |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
242 |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
243 if (res == (size_t) -1) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
244 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
245 /* The string cannot be converted. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
246 if (use_malloc) |
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 free (wmessage); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
249 use_malloc = false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
250 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
251 wmessage = (wchar_t *) L"???"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
252 } |
3446 | 253 |
254 __vfwprintf (stderr, wmessage, args); | |
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 (use_malloc) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
257 free (wmessage); |
3446 | 258 } |
259 else | |
4695 | 260 #endif |
3446 | 261 vfprintf (stderr, message, args); |
262 va_end (args); | |
263 | |
264 ++error_message_count; | |
265 if (errnum) | |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
266 print_errno_message (errnum); |
4680
0ec32cb1202f
Correct indentation of cpp directives.
Jim Meyering <jim@meyering.net>
parents:
4636
diff
changeset
|
267 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
268 __fxprintf (NULL, "\n"); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
269 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
270 putc ('\n', stderr); |
4680
0ec32cb1202f
Correct indentation of cpp directives.
Jim Meyering <jim@meyering.net>
parents:
4636
diff
changeset
|
271 #endif |
3446 | 272 fflush (stderr); |
273 if (status) | |
274 exit (status); | |
275 } | |
276 | |
277 | |
9 | 278 /* Print the program name and error message MESSAGE, which is a printf-style |
279 format string with optional args. | |
280 If ERRNUM is nonzero, print its corresponding system error message. | |
281 Exit with status STATUS if it is nonzero. */ | |
282 void | |
398 | 283 error (int status, int errnum, const char *message, ...) |
9 | 284 { |
285 va_list args; | |
286 | |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
287 #if defined _LIBC && defined __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
288 /* 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
|
289 cancellation. Therefore disable cancellation for now. */ |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
290 int state = PTHREAD_CANCEL_ENABLE; |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
291 __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
|
292 0); |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
293 #endif |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
294 |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
295 flush_stdout (); |
3446 | 296 #ifdef _LIBC |
297 _IO_flockfile (stderr); | |
298 #endif | |
398 | 299 if (error_print_progname) |
300 (*error_print_progname) (); | |
301 else | |
302 { | |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
303 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
304 __fxprintf (NULL, "%s: ", program_name); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
305 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
306 fprintf (stderr, "%s: ", program_name); |
3446 | 307 #endif |
398 | 308 } |
309 | |
4636 | 310 va_start (args, message); |
3446 | 311 error_tail (status, errnum, message, args); |
312 | |
313 #ifdef _LIBC | |
314 _IO_funlockfile (stderr); | |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
315 # ifdef __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
316 __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
317 # endif |
3446 | 318 #endif |
9 | 319 } |
572 | 320 |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
321 /* 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
|
322 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
|
323 int error_one_per_line; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
324 |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
325 void |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
326 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
|
327 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
|
328 { |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
329 va_list args; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
330 |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
331 if (error_one_per_line) |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
332 { |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
333 static const char *old_file_name; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
334 static unsigned int old_line_number; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
335 |
3446 | 336 if (old_line_number == line_number |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
337 && (file_name == old_file_name |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
338 || strcmp (old_file_name, file_name) == 0)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
339 /* Simply return and print nothing. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
340 return; |
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 old_file_name = file_name; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
343 old_line_number = line_number; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
344 } |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
345 |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
346 #if defined _LIBC && defined __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
347 /* 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
|
348 cancellation. Therefore disable cancellation for now. */ |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
349 int state = PTHREAD_CANCEL_ENABLE; |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
350 __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
|
351 0); |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
352 #endif |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
353 |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
354 flush_stdout (); |
3446 | 355 #ifdef _LIBC |
356 _IO_flockfile (stderr); | |
357 #endif | |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
358 if (error_print_progname) |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
359 (*error_print_progname) (); |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
360 else |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
361 { |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
362 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
363 __fxprintf (NULL, "%s:", program_name); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
364 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
365 fprintf (stderr, "%s:", program_name); |
3446 | 366 #endif |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
367 } |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
368 |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
369 #if _LIBC |
7131
02e62250d524
* misc/error.c: Add space between program name and message if file
Eric Blake <ebb9@byu.net>
parents:
7088
diff
changeset
|
370 __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
371 file_name, line_number); |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
372 #else |
7131
02e62250d524
* misc/error.c: Add space between program name and message if file
Eric Blake <ebb9@byu.net>
parents:
7088
diff
changeset
|
373 fprintf (stderr, file_name != NULL ? "%s:%d: " : " ", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
374 file_name, line_number); |
3446 | 375 #endif |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
376 |
4636 | 377 va_start (args, message); |
3446 | 378 error_tail (status, errnum, message, args); |
379 | |
380 #ifdef _LIBC | |
381 _IO_funlockfile (stderr); | |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
382 # ifdef __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
383 __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
384 # endif |
3446 | 385 #endif |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
386 } |
1268 | 387 |
388 #ifdef _LIBC | |
389 /* Make the weak alias. */ | |
1289 | 390 # undef error |
391 # undef error_at_line | |
1268 | 392 weak_alias (__error, error) |
393 weak_alias (__error_at_line, error_at_line) | |
394 #endif |