Mercurial > hg > octave-jordi > gnulib-hg
annotate lib/error.c @ 16214:ec738d6aeef5
Talk about "native Windows API", not "Win32".
* lib/classpath.c: Update comments to mention native Windows.
* lib/csharpexec.c: Likewise.
* lib/dup2.c: Likewise.
* lib/error.c: Likewise.
* lib/fcntl.c: Likewise.
* lib/filename.h: Likewise.
* lib/findprog.c: Likewise.
* lib/get-rusage-as.c: Likewise.
* lib/get-rusage-data.c: Likewise.
* lib/getpagesize.c: Likewise.
* lib/javaexec.c: Likewise.
* lib/msvc-inval.c: Likewise.
* lib/msvc-nothrow.c: Likewise.
* lib/nanosleep.c: Likewise.
* lib/nonblocking.c: Likewise.
* lib/printf-parse.c: Likewise.
* lib/setlocale.c: Likewise.
* lib/sigaction.c: Likewise.
* lib/strerror_r.c: Likewise.
* lib/tmpdir.c: Likewise.
* lib/vasnprintf.c: Likewise.
* lib/w32spawn.h: Likewise.
* lib/waitpid.c: Likewise.
* lib/stdio.in.h (fdopen, fopen, freopen): Likewise.
* m4/locale-ar.m4: Likewise.
* m4/locale-fr.m4: Likewise.
* m4/locale-ja.m4: Likewise.
* m4/locale-tr.m4: Likewise.
* m4/locale-zh.m4: Likewise.
* m4/printf.m4: Likewise.
* tests/test-cloexec.c: Likewise.
* tests/test-copy-acl.sh: Likewise.
* tests/test-copy-file.sh: Likewise.
* tests/test-file-has-acl.sh: Likewise.
* tests/test-set-mode-acl.sh: Likewise.
* tests/test-dup-safer.c: Likewise.
* tests/test-dup2.c: Likewise.
* tests/test-dup3.c: Likewise.
* tests/test-fcntl.c: Likewise.
* tests/test-nonblocking-pipe.h: Likewise.
* tests/test-nonblocking-socket.h: Likewise.
* tests/test-pipe.c: Likewise.
* tests/test-pipe2.c: Likewise.
* tests/test-spawn-pipe-child.c: Likewise.
* doc/acl-resources.txt: Likewise.
* lib/getaddrinfo.c (WINDOWS_NATIVE): Renamed from WIN32_NATIVE.
* tests/test-poll.c (WINDOWS_NATIVE): Likewise.
* tests/test-select.h (WINDOWS_NATIVE): Likewise.
* lib/localcharset.c: Update comments to mention native Windows.
(WINDOWS_NATIVE): Renamed from WIN32_NATIVE.
* lib/localename.c: Likewise.
* lib/progreloc.c: Likewise.
* lib/relocatable.c: Likewise.
* lib/poll.c (WINDOWS_NATIVE): Renamed from WIN32_NATIVE.
(windows_compute_revents): Renamed from win32_compute_revents.
(windows_compute_revents_socket): Renamed from
win32_compute_revents_socket.
* lib/select.c: Update comments to mention native Windows.
(windows_poll_handle): Renamed from win32_poll_handle.
* m4/threadlib.m4: Update comments to mention native Windows.
(gl_THREADLIB_EARLY_BODY, gl_THREADLIB_BODY): Expect
--enable-threads=windows instead of --enable-threads=win32. Set
USE_WINDOWS_THREADS, not USE_WIN32_THREADS.
* lib/glthread/lock.h: Update comments to mention native Windows.
(USE_WINDOWS_THREADS): Renamed from USE_WIN32_THREADS.
* lib/glthread/lock.c (USE_WINDOWS_THREADS): Renamed from
USE_WIN32_THREADS.
* lib/glthread/cond.h (USE_WINDOWS_THREADS): Likewise.
* lib/glthread/cond.c (USE_WINDOWS_THREADS): Likewise.
* lib/glthread/thread.h (USE_WINDOWS_THREADS): Likewise.
* lib/glthread/thread.c (USE_WINDOWS_THREADS): Likewise.
* lib/glthread/tls.h (USE_WINDOWS_THREADS): Likewise.
* lib/glthread/tls.c (USE_WINDOWS_THREADS): Likewise.
* lib/glthread/yield.h (USE_WINDOWS_THREADS): Likewise.
* tests/test-cond.c (USE_WINDOWS_THREADS): Likewise.
* tests/test-thread_create.c (USE_WINDOWS_THREADS): Likewise.
* tests/test-lock.c (USE_WINDOWS_THREADS): Likewise.
(TEST_WINDOWS_THREADS): Renamed from TEST_WIN32_THREADS.
* tests/test-tls.c: Likewise.
Rationale:
Microsoft renamed the "Win32 API" to "Windows API", as it is available
on both 32-bit and 64-bit Windows systems.
But in gnulib, we treat Cygwin like a Unix platform, therefore the main
line of distinction is between "native Windows" on one side and Unix/
POSIX systems on the other side. More details in
<https://lists.gnu.org/archive/html/bug-gnulib/2012-01/msg00027.html>.
Suggested by Paul Eggert.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Wed, 04 Jan 2012 14:31:33 +0100 |
parents | 8250f2777afc |
children | 18a38c9615f0 |
rev | line source |
---|---|
1268 | 1 /* Error handler for noninteractive utilities |
16201
8250f2777afc
maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents:
15752
diff
changeset
|
2 Copyright (C) 1990-1998, 2000-2007, 2009-2012 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__ |
16214
ec738d6aeef5
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
92 /* 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
|
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> |
15752
b86e9061a6d0
New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
14868
diff
changeset
|
95 /* Get _get_osfhandle. */ |
b86e9061a6d0
New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9.
Bruno Haible <bruno@clisp.org>
parents:
14868
diff
changeset
|
96 # include "msvc-nothrow.h" |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
97 # endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
98 |
13326
9a066ce4a8a5
error: Use system's fcntl function.
Bruno Haible <bruno@clisp.org>
parents:
13324
diff
changeset
|
99 /* 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
|
100 # undef fcntl |
9a066ce4a8a5
error: Use system's fcntl function.
Bruno Haible <bruno@clisp.org>
parents:
13324
diff
changeset
|
101 |
14868 | 102 # if !HAVE_DECL_STRERROR_R |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
103 # ifndef HAVE_DECL_STRERROR_R |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
104 "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
|
105 # endif |
14868 | 106 # if STRERROR_R_CHAR_P |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
107 char *strerror_r (); |
14868 | 108 # else |
109 int strerror_r (); | |
110 # endif | |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
111 # endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
112 |
398 | 113 /* The calling program should define program_name and set it to the |
114 name of the executing program. */ | |
115 extern char *program_name; | |
9 | 116 |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
117 # if HAVE_STRERROR_R || defined strerror_r |
1289 | 118 # define __strerror_r strerror_r |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
119 # endif /* HAVE_STRERROR_R || defined strerror_r */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
120 #endif /* not _LIBC */ |
9 | 121 |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
122 #if !_LIBC |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
123 /* Return non-zero if FD is open. */ |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
124 static inline int |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
125 is_open (int fd) |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
126 { |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
127 # 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
|
128 /* 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
|
129 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
|
130 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
|
131 F_GETFL. */ |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
132 return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE; |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
133 # else |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
134 # ifndef F_GETFL |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
135 # error Please port fcntl to your platform |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
136 # endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
137 return 0 <= fcntl (fd, F_GETFL); |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
138 # endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
139 } |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
140 #endif |
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
141 |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
142 static inline void |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
143 flush_stdout (void) |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
144 { |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
145 #if !_LIBC |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
146 int stdout_fd; |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
147 |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
148 # if GNULIB_FREOPEN_SAFER |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
149 /* 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
|
150 fileno (stdout) == 1 |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
151 whenever stdout is open. */ |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
152 stdout_fd = STDOUT_FILENO; |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
153 # else |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
154 /* 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
|
155 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
|
156 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
|
157 stdout_fd = fileno (stdout); |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
158 # endif |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
159 /* 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
|
160 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
|
161 is always defined, but too draconian. */ |
13324
2792eeac632f
error: More reliable output on mingw.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
162 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
|
163 #endif |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
164 fflush (stdout); |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
165 } |
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
166 |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
167 static void |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
168 print_errno_message (int errnum) |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
169 { |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
170 char const *s; |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
171 |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
172 #if defined HAVE_STRERROR_R || _LIBC |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
173 char errbuf[1024]; |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
174 # if STRERROR_R_CHAR_P || _LIBC |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
175 s = __strerror_r (errnum, errbuf, sizeof errbuf); |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
176 # else |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
177 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
|
178 s = errbuf; |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
179 else |
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
180 s = 0; |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
181 # endif |
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 = strerror (errnum); |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
184 #endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
185 |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
186 #if !_LIBC |
7232
b307709e3a05
* error.c (error_at_line, print_errno_message): Match libc, after
Eric Blake <ebb9@byu.net>
parents:
7131
diff
changeset
|
187 if (! s) |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
188 s = _("Unknown system error"); |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
189 #endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
190 |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
191 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
192 __fxprintf (NULL, ": %s", s); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
193 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
194 fprintf (stderr, ": %s", s); |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
195 #endif |
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
196 } |
3446 | 197 |
198 static void | |
199 error_tail (int status, int errnum, const char *message, va_list args) | |
200 { | |
4695 | 201 #if _LIBC |
3446 | 202 if (_IO_fwide (stderr, 0) > 0) |
203 { | |
4695 | 204 # define ALLOCA_LIMIT 2000 |
3446 | 205 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
|
206 wchar_t *wmessage = NULL; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
207 mbstate_t st; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
208 size_t res; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
209 const char *tmp; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
210 bool use_malloc = false; |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
211 |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
212 while (1) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
213 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
214 if (__libc_use_alloca (len * sizeof (wchar_t))) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
215 wmessage = (wchar_t *) alloca (len * sizeof (wchar_t)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
216 else |
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 if (!use_malloc) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
219 wmessage = NULL; |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
220 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
221 wchar_t *p = (wchar_t *) realloc (wmessage, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
222 len * sizeof (wchar_t)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
223 if (p == NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
224 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
225 free (wmessage); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
226 fputws_unlocked (L"out of memory\n", stderr); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
227 return; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
228 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
229 wmessage = p; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
230 use_malloc = true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
231 } |
3446 | 232 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
233 memset (&st, '\0', sizeof (st)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
234 tmp = message; |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
235 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
236 res = mbsrtowcs (wmessage, &tmp, len, &st); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
237 if (res != len) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
238 break; |
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 if (__builtin_expect (len >= SIZE_MAX / 2, 0)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
241 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
242 /* 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
|
243 res = (size_t) -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
244 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
245 } |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
246 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
247 len *= 2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
248 } |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
249 |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
250 if (res == (size_t) -1) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
251 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
252 /* The string cannot be converted. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
253 if (use_malloc) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
254 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
255 free (wmessage); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
256 use_malloc = false; |
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 wmessage = (wchar_t *) L"???"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
259 } |
3446 | 260 |
261 __vfwprintf (stderr, wmessage, args); | |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
262 |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
263 if (use_malloc) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
264 free (wmessage); |
3446 | 265 } |
266 else | |
4695 | 267 #endif |
3446 | 268 vfprintf (stderr, message, args); |
269 va_end (args); | |
270 | |
271 ++error_message_count; | |
272 if (errnum) | |
3550
c18604dda2d7
(strerror_r): Do not declare unless !_LIBC.
Jim Meyering <jim@meyering.net>
parents:
3446
diff
changeset
|
273 print_errno_message (errnum); |
4680
0ec32cb1202f
Correct indentation of cpp directives.
Jim Meyering <jim@meyering.net>
parents:
4636
diff
changeset
|
274 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
275 __fxprintf (NULL, "\n"); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
276 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
277 putc ('\n', stderr); |
4680
0ec32cb1202f
Correct indentation of cpp directives.
Jim Meyering <jim@meyering.net>
parents:
4636
diff
changeset
|
278 #endif |
3446 | 279 fflush (stderr); |
280 if (status) | |
281 exit (status); | |
282 } | |
283 | |
284 | |
9 | 285 /* Print the program name and error message MESSAGE, which is a printf-style |
286 format string with optional args. | |
287 If ERRNUM is nonzero, print its corresponding system error message. | |
288 Exit with status STATUS if it is nonzero. */ | |
289 void | |
398 | 290 error (int status, int errnum, const char *message, ...) |
9 | 291 { |
292 va_list args; | |
293 | |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
294 #if defined _LIBC && defined __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
295 /* 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
|
296 cancellation. Therefore disable cancellation for now. */ |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
297 int state = PTHREAD_CANCEL_ENABLE; |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
298 __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
|
299 0); |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
300 #endif |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
301 |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
302 flush_stdout (); |
3446 | 303 #ifdef _LIBC |
304 _IO_flockfile (stderr); | |
305 #endif | |
398 | 306 if (error_print_progname) |
307 (*error_print_progname) (); | |
308 else | |
309 { | |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
310 #if _LIBC |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
311 __fxprintf (NULL, "%s: ", program_name); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
312 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
313 fprintf (stderr, "%s: ", program_name); |
3446 | 314 #endif |
398 | 315 } |
316 | |
4636 | 317 va_start (args, message); |
3446 | 318 error_tail (status, errnum, message, args); |
319 | |
320 #ifdef _LIBC | |
321 _IO_funlockfile (stderr); | |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
322 # ifdef __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
323 __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
324 # endif |
3446 | 325 #endif |
9 | 326 } |
572 | 327 |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
328 /* 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
|
329 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
|
330 int error_one_per_line; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
331 |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
332 void |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
333 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
|
334 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
|
335 { |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
336 va_list args; |
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 if (error_one_per_line) |
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 static const char *old_file_name; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
341 static unsigned int old_line_number; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
342 |
3446 | 343 if (old_line_number == line_number |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
344 && (file_name == old_file_name |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
345 || strcmp (old_file_name, file_name) == 0)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
346 /* Simply return and print nothing. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
347 return; |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
348 |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
349 old_file_name = file_name; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
350 old_line_number = line_number; |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
351 } |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
352 |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
353 #if defined _LIBC && defined __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
354 /* 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
|
355 cancellation. Therefore disable cancellation for now. */ |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
356 int state = PTHREAD_CANCEL_ENABLE; |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
357 __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
|
358 0); |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
359 #endif |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
360 |
12337
9d131fdf3903
error: account for the possibility of freopen (stdout).
Bruno Haible <bruno@clisp.org>
parents:
11714
diff
changeset
|
361 flush_stdout (); |
3446 | 362 #ifdef _LIBC |
363 _IO_flockfile (stderr); | |
364 #endif | |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
365 if (error_print_progname) |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
366 (*error_print_progname) (); |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
367 else |
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 |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
370 __fxprintf (NULL, "%s:", program_name); |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
371 #else |
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
372 fprintf (stderr, "%s:", program_name); |
3446 | 373 #endif |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
374 } |
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
375 |
4500
cdb224406ea7
[!USE_IN_LIBIO]: Omit this case; assume USE_IN_LIBIO is 1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4072
diff
changeset
|
376 #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
|
377 __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
378 file_name, line_number); |
7088
e3cb6c0685d8
* error.h: Fold in some upstream changes from glibc.
Eric Blake <ebb9@byu.net>
parents:
5848
diff
changeset
|
379 #else |
7131
02e62250d524
* misc/error.c: Add space between program name and message if file
Eric Blake <ebb9@byu.net>
parents:
7088
diff
changeset
|
380 fprintf (stderr, file_name != NULL ? "%s:%d: " : " ", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
12338
diff
changeset
|
381 file_name, line_number); |
3446 | 382 #endif |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
383 |
4636 | 384 va_start (args, message); |
3446 | 385 error_tail (status, errnum, message, args); |
386 | |
387 #ifdef _LIBC | |
388 _IO_funlockfile (stderr); | |
4739
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
389 # ifdef __libc_ptf_call |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
390 __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); |
04758f7475fd
Merge changes from glibc.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4695
diff
changeset
|
391 # endif |
3446 | 392 #endif |
573
8a90f3b04017
update from FSF:/home/gd/gnu/lib
Jim Meyering <jim@meyering.net>
parents:
572
diff
changeset
|
393 } |
1268 | 394 |
395 #ifdef _LIBC | |
396 /* Make the weak alias. */ | |
1289 | 397 # undef error |
398 # undef error_at_line | |
1268 | 399 weak_alias (__error, error) |
400 weak_alias (__error_at_line, error_at_line) | |
401 #endif |