diff options
author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2022-08-23 19:42:51 +0200 |
---|---|---|
committer | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2022-09-14 11:08:55 +0200 |
commit | 868beb15ae02c352005a2df8857f4ebb9bd758fd (patch) | |
tree | 0dc6e6a91c4ef0f131ca82a777e6ac2ad193c399 /gl/error.c | |
parent | b89aee56964f7d933f2da5f371e32b4d7db9410b (diff) | |
download | monitoring-plugins-868beb1.tar.gz |
Sync with the latest Gnulib code (d27c820595)
Diffstat (limited to 'gl/error.c')
-rw-r--r-- | gl/error.c | 74 |
1 files changed, 42 insertions, 32 deletions
@@ -1,19 +1,19 @@ | |||
1 | /* Error handler for noninteractive utilities | 1 | /* Error handler for noninteractive utilities |
2 | Copyright (C) 1990-1998, 2000-2007, 2009-2013 Free Software Foundation, Inc. | 2 | Copyright (C) 1990-1998, 2000-2007, 2009-2022 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
4 | 4 | ||
5 | This program is free software: you can redistribute it and/or modify | 5 | This file is free software: you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU Lesser General Public License as |
7 | the Free Software Foundation; either version 3 of the License, or | 7 | published by the Free Software Foundation; either version 2.1 of the |
8 | (at your option) any later version. | 8 | License, or (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This file is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU Lesser General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Lesser General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | 16 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
17 | 17 | ||
18 | /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */ | 18 | /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */ |
19 | 19 | ||
@@ -39,6 +39,11 @@ | |||
39 | # include <stdint.h> | 39 | # include <stdint.h> |
40 | # include <wchar.h> | 40 | # include <wchar.h> |
41 | # define mbsrtowcs __mbsrtowcs | 41 | # define mbsrtowcs __mbsrtowcs |
42 | # define USE_UNLOCKED_IO 0 | ||
43 | # define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(a, b) | ||
44 | # define _GL_ARG_NONNULL(a) | ||
45 | #else | ||
46 | # include "getprogname.h" | ||
42 | #endif | 47 | #endif |
43 | 48 | ||
44 | #if USE_UNLOCKED_IO | 49 | #if USE_UNLOCKED_IO |
@@ -72,14 +77,14 @@ extern void __error (int status, int errnum, const char *message, ...) | |||
72 | extern void __error_at_line (int status, int errnum, const char *file_name, | 77 | extern void __error_at_line (int status, int errnum, const char *file_name, |
73 | unsigned int line_number, const char *message, | 78 | unsigned int line_number, const char *message, |
74 | ...) | 79 | ...) |
75 | __attribute__ ((__format__ (__printf__, 5, 6)));; | 80 | __attribute__ ((__format__ (__printf__, 5, 6))); |
76 | # define error __error | 81 | # define error __error |
77 | # define error_at_line __error_at_line | 82 | # define error_at_line __error_at_line |
78 | 83 | ||
79 | # include <libio/iolibio.h> | 84 | # include <libio/iolibio.h> |
80 | # define fflush(s) INTUSE(_IO_fflush) (s) | 85 | # define fflush(s) _IO_fflush (s) |
81 | # undef putc | 86 | # undef putc |
82 | # define putc(c, fp) INTUSE(_IO_putc) (c, fp) | 87 | # define putc(c, fp) _IO_putc (c, fp) |
83 | 88 | ||
84 | # include <bits/libc-lock.h> | 89 | # include <bits/libc-lock.h> |
85 | 90 | ||
@@ -88,35 +93,37 @@ extern void __error_at_line (int status, int errnum, const char *file_name, | |||
88 | # include <fcntl.h> | 93 | # include <fcntl.h> |
89 | # include <unistd.h> | 94 | # include <unistd.h> |
90 | 95 | ||
91 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | 96 | # if defined _WIN32 && ! defined __CYGWIN__ |
92 | /* Get declarations of the native Windows API functions. */ | 97 | /* Get declarations of the native Windows API functions. */ |
93 | # define WIN32_LEAN_AND_MEAN | 98 | # define WIN32_LEAN_AND_MEAN |
94 | # include <windows.h> | 99 | # include <windows.h> |
95 | /* Get _get_osfhandle. */ | 100 | /* Get _get_osfhandle. */ |
96 | # include "msvc-nothrow.h" | 101 | # if GNULIB_MSVC_NOTHROW |
102 | # include "msvc-nothrow.h" | ||
103 | # else | ||
104 | # include <io.h> | ||
105 | # endif | ||
97 | # endif | 106 | # endif |
98 | 107 | ||
99 | /* The gnulib override of fcntl is not needed in this file. */ | 108 | /* The gnulib override of fcntl is not needed in this file. */ |
100 | # undef fcntl | 109 | # undef fcntl |
101 | 110 | ||
102 | # if !HAVE_DECL_STRERROR_R | 111 | # if !(GNULIB_STRERROR_R_POSIX || HAVE_DECL_STRERROR_R) |
103 | # ifndef HAVE_DECL_STRERROR_R | 112 | # ifndef HAVE_DECL_STRERROR_R |
104 | "this configure-time declaration test was not run" | 113 | "this configure-time declaration test was not run" |
105 | # endif | 114 | # endif |
106 | # if STRERROR_R_CHAR_P | 115 | # if STRERROR_R_CHAR_P |
107 | char *strerror_r (); | 116 | char *strerror_r (int errnum, char *buf, size_t buflen); |
108 | # else | 117 | # else |
109 | int strerror_r (); | 118 | int strerror_r (int errnum, char *buf, size_t buflen); |
110 | # endif | 119 | # endif |
111 | # endif | 120 | # endif |
112 | 121 | ||
113 | /* The calling program should define program_name and set it to the | 122 | # define program_name getprogname () |
114 | name of the executing program. */ | ||
115 | extern char *program_name; | ||
116 | 123 | ||
117 | # if HAVE_STRERROR_R || defined strerror_r | 124 | # if GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r |
118 | # define __strerror_r strerror_r | 125 | # define __strerror_r strerror_r |
119 | # endif /* HAVE_STRERROR_R || defined strerror_r */ | 126 | # endif /* GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r */ |
120 | #endif /* not _LIBC */ | 127 | #endif /* not _LIBC */ |
121 | 128 | ||
122 | #if !_LIBC | 129 | #if !_LIBC |
@@ -124,7 +131,7 @@ extern char *program_name; | |||
124 | static int | 131 | static int |
125 | is_open (int fd) | 132 | is_open (int fd) |
126 | { | 133 | { |
127 | # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | 134 | # if defined _WIN32 && ! defined __CYGWIN__ |
128 | /* On native Windows: The initial state of unassigned standard file | 135 | /* On native Windows: The initial state of unassigned standard file |
129 | descriptors is that they are open but point to an INVALID_HANDLE_VALUE. | 136 | descriptors is that they are open but point to an INVALID_HANDLE_VALUE. |
130 | There is no fcntl, and the gnulib replacement fcntl does not support | 137 | There is no fcntl, and the gnulib replacement fcntl does not support |
@@ -169,9 +176,9 @@ print_errno_message (int errnum) | |||
169 | { | 176 | { |
170 | char const *s; | 177 | char const *s; |
171 | 178 | ||
172 | #if defined HAVE_STRERROR_R || _LIBC | 179 | #if _LIBC || GNULIB_STRERROR_R_POSIX || defined HAVE_STRERROR_R |
173 | char errbuf[1024]; | 180 | char errbuf[1024]; |
174 | # if STRERROR_R_CHAR_P || _LIBC | 181 | # if _LIBC || (!GNULIB_STRERROR_R_POSIX && STRERROR_R_CHAR_P) |
175 | s = __strerror_r (errnum, errbuf, sizeof errbuf); | 182 | s = __strerror_r (errnum, errbuf, sizeof errbuf); |
176 | # else | 183 | # else |
177 | if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0) | 184 | if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0) |
@@ -195,13 +202,12 @@ print_errno_message (int errnum) | |||
195 | #endif | 202 | #endif |
196 | } | 203 | } |
197 | 204 | ||
198 | static void | 205 | static void _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0) _GL_ARG_NONNULL ((3)) |
199 | error_tail (int status, int errnum, const char *message, va_list args) | 206 | error_tail (int status, int errnum, const char *message, va_list args) |
200 | { | 207 | { |
201 | #if _LIBC | 208 | #if _LIBC |
202 | if (_IO_fwide (stderr, 0) > 0) | 209 | if (_IO_fwide (stderr, 0) > 0) |
203 | { | 210 | { |
204 | # define ALLOCA_LIMIT 2000 | ||
205 | size_t len = strlen (message) + 1; | 211 | size_t len = strlen (message) + 1; |
206 | wchar_t *wmessage = NULL; | 212 | wchar_t *wmessage = NULL; |
207 | mbstate_t st; | 213 | mbstate_t st; |
@@ -237,7 +243,7 @@ error_tail (int status, int errnum, const char *message, va_list args) | |||
237 | if (res != len) | 243 | if (res != len) |
238 | break; | 244 | break; |
239 | 245 | ||
240 | if (__builtin_expect (len >= SIZE_MAX / 2, 0)) | 246 | if (__builtin_expect (len >= SIZE_MAX / sizeof (wchar_t) / 2, 0)) |
241 | { | 247 | { |
242 | /* This really should not happen if everything is fine. */ | 248 | /* This really should not happen if everything is fine. */ |
243 | res = (size_t) -1; | 249 | res = (size_t) -1; |
@@ -266,7 +272,6 @@ error_tail (int status, int errnum, const char *message, va_list args) | |||
266 | else | 272 | else |
267 | #endif | 273 | #endif |
268 | vfprintf (stderr, message, args); | 274 | vfprintf (stderr, message, args); |
269 | va_end (args); | ||
270 | 275 | ||
271 | ++error_message_count; | 276 | ++error_message_count; |
272 | if (errnum) | 277 | if (errnum) |
@@ -316,6 +321,7 @@ error (int status, int errnum, const char *message, ...) | |||
316 | 321 | ||
317 | va_start (args, message); | 322 | va_start (args, message); |
318 | error_tail (status, errnum, message, args); | 323 | error_tail (status, errnum, message, args); |
324 | va_end (args); | ||
319 | 325 | ||
320 | #ifdef _LIBC | 326 | #ifdef _LIBC |
321 | _IO_funlockfile (stderr); | 327 | _IO_funlockfile (stderr); |
@@ -342,7 +348,10 @@ error_at_line (int status, int errnum, const char *file_name, | |||
342 | 348 | ||
343 | if (old_line_number == line_number | 349 | if (old_line_number == line_number |
344 | && (file_name == old_file_name | 350 | && (file_name == old_file_name |
345 | || strcmp (old_file_name, file_name) == 0)) | 351 | || (old_file_name != NULL |
352 | && file_name != NULL | ||
353 | && strcmp (old_file_name, file_name) == 0))) | ||
354 | |||
346 | /* Simply return and print nothing. */ | 355 | /* Simply return and print nothing. */ |
347 | return; | 356 | return; |
348 | 357 | ||
@@ -374,15 +383,16 @@ error_at_line (int status, int errnum, const char *file_name, | |||
374 | } | 383 | } |
375 | 384 | ||
376 | #if _LIBC | 385 | #if _LIBC |
377 | __fxprintf (NULL, file_name != NULL ? "%s:%d: " : " ", | 386 | __fxprintf (NULL, file_name != NULL ? "%s:%u: " : " ", |
378 | file_name, line_number); | 387 | file_name, line_number); |
379 | #else | 388 | #else |
380 | fprintf (stderr, file_name != NULL ? "%s:%d: " : " ", | 389 | fprintf (stderr, file_name != NULL ? "%s:%u: " : " ", |
381 | file_name, line_number); | 390 | file_name, line_number); |
382 | #endif | 391 | #endif |
383 | 392 | ||
384 | va_start (args, message); | 393 | va_start (args, message); |
385 | error_tail (status, errnum, message, args); | 394 | error_tail (status, errnum, message, args); |
395 | va_end (args); | ||
386 | 396 | ||
387 | #ifdef _LIBC | 397 | #ifdef _LIBC |
388 | _IO_funlockfile (stderr); | 398 | _IO_funlockfile (stderr); |