diff options
Diffstat (limited to 'gl/error.in.h')
| -rw-r--r-- | gl/error.in.h | 261 |
1 files changed, 261 insertions, 0 deletions
diff --git a/gl/error.in.h b/gl/error.in.h new file mode 100644 index 00000000..6c512ec8 --- /dev/null +++ b/gl/error.in.h | |||
| @@ -0,0 +1,261 @@ | |||
| 1 | /* Declarations for error-reporting functions. | ||
| 2 | Copyright (C) 1995-1997, 2003, 2006, 2008-2025 Free Software Foundation, | ||
| 3 | Inc. | ||
| 4 | This file is part of the GNU C Library. | ||
| 5 | |||
| 6 | This file is free software: you can redistribute it and/or modify | ||
| 7 | it under the terms of the GNU Lesser General Public License as | ||
| 8 | published by the Free Software Foundation; either version 2.1 of the | ||
| 9 | License, or (at your option) any later version. | ||
| 10 | |||
| 11 | This file is distributed in the hope that it will be useful, | ||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU Lesser General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU Lesser General Public License | ||
| 17 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #ifndef _@GUARD_PREFIX@_ERROR_H | ||
| 20 | |||
| 21 | /* No @PRAGMA_SYSTEM_HEADER@ here, because it would prevent | ||
| 22 | -Wimplicit-fallthrough warnings for missing FALLTHROUGH after error(...) | ||
| 23 | or error_at_line(...) invocations. */ | ||
| 24 | |||
| 25 | /* The include_next requires a split double-inclusion guard. */ | ||
| 26 | #if @HAVE_ERROR_H@ && !defined __MINGW32__ | ||
| 27 | # @INCLUDE_NEXT@ @NEXT_ERROR_H@ | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #ifndef _@GUARD_PREFIX@_ERROR_H | ||
| 31 | #define _@GUARD_PREFIX@_ERROR_H | ||
| 32 | |||
| 33 | /* This file uses _GL_ATTRIBUTE_ALWAYS_INLINE, _GL_ATTRIBUTE_COLD, | ||
| 34 | _GL_ATTRIBUTE_FORMAT, _GL_ATTRIBUTE_MAYBE_UNUSED. */ | ||
| 35 | #if !_GL_CONFIG_H_INCLUDED | ||
| 36 | #error "Please include config.h first." | ||
| 37 | #endif | ||
| 38 | |||
| 39 | /* Get va_list. */ | ||
| 40 | #include <stdarg.h> | ||
| 41 | |||
| 42 | /* Get 'gl_unreachable'. */ | ||
| 43 | #include <stddef.h> | ||
| 44 | |||
| 45 | /* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM. */ | ||
| 46 | #include <stdio.h> | ||
| 47 | |||
| 48 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ | ||
| 49 | |||
| 50 | #if GNULIB_VFPRINTF_POSIX | ||
| 51 | # define _GL_ATTRIBUTE_SPEC_PRINTF_ERROR _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD | ||
| 52 | #else | ||
| 53 | # define _GL_ATTRIBUTE_SPEC_PRINTF_ERROR _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM | ||
| 54 | #endif | ||
| 55 | |||
| 56 | /* Helper macro for supporting the compiler's control flow analysis better. | ||
| 57 | It evaluates its arguments only once. | ||
| 58 | Test case: Compile copy-file.c with "gcc -Wimplicit-fallthrough". */ | ||
| 59 | #if defined __GNUC__ || defined __clang__ | ||
| 60 | /* Use 'gl_unreachable' to tell the compiler when the function call does not | ||
| 61 | return. */ | ||
| 62 | # define __gl_error_call1(function, status, ...) \ | ||
| 63 | ((function) (status, __VA_ARGS__), \ | ||
| 64 | (status) != 0 ? gl_unreachable () : (void) 0) | ||
| 65 | /* If STATUS is a not a constant, the function call may or may not return; | ||
| 66 | therefore -Wimplicit-fallthrough will produce a warning. Use a compound | ||
| 67 | statement in order to evaluate STATUS only once. | ||
| 68 | If STATUS is a constant, we don't use a compound statement, because that | ||
| 69 | would trigger a -Wimplicit-fallthrough warning even when STATUS is != 0, | ||
| 70 | when not optimizing. This causes STATUS to be evaluated twice, but | ||
| 71 | that's OK since it does not have side effects. */ | ||
| 72 | # define __gl_error_call(function, status, ...) \ | ||
| 73 | (__builtin_constant_p (status) \ | ||
| 74 | ? __gl_error_call1 (function, status, __VA_ARGS__) \ | ||
| 75 | : __extension__ \ | ||
| 76 | ({ \ | ||
| 77 | int const __errstatus = status; \ | ||
| 78 | __gl_error_call1 (function, __errstatus, __VA_ARGS__); \ | ||
| 79 | })) | ||
| 80 | #else | ||
| 81 | # define __gl_error_call(function, status, ...) \ | ||
| 82 | (function) (status, __VA_ARGS__) | ||
| 83 | #endif | ||
| 84 | |||
| 85 | #ifdef __cplusplus | ||
| 86 | extern "C" { | ||
| 87 | #endif | ||
| 88 | |||
| 89 | /* Print a message with 'fprintf (stderr, FORMAT, ...)'; | ||
| 90 | if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). | ||
| 91 | If STATUS is nonzero, terminate the program with 'exit (STATUS)'. */ | ||
| 92 | #if @REPLACE_ERROR@ | ||
| 93 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 94 | # undef error | ||
| 95 | # define error rpl_error | ||
| 96 | # endif | ||
| 97 | _GL_FUNCDECL_RPL (error, void, | ||
| 98 | (int __status, int __errnum, const char *__format, ...), | ||
| 99 | _GL_ATTRIBUTE_COLD | ||
| 100 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 3, 4))); | ||
| 101 | _GL_CXXALIAS_RPL (error, void, | ||
| 102 | (int __status, int __errnum, const char *__format, ...)); | ||
| 103 | # ifndef _GL_NO_INLINE_ERROR | ||
| 104 | # undef error | ||
| 105 | # define error(status, ...) \ | ||
| 106 | __gl_error_call (rpl_error, status, __VA_ARGS__) | ||
| 107 | # endif | ||
| 108 | #else | ||
| 109 | # if ! @HAVE_ERROR@ | ||
| 110 | _GL_FUNCDECL_SYS (error, void, | ||
| 111 | (int __status, int __errnum, const char *__format, ...), | ||
| 112 | _GL_ATTRIBUTE_COLD | ||
| 113 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 3, 4))); | ||
| 114 | # endif | ||
| 115 | _GL_CXXALIAS_SYS (error, void, | ||
| 116 | (int __status, int __errnum, const char *__format, ...)); | ||
| 117 | # ifndef _GL_NO_INLINE_ERROR | ||
| 118 | # ifdef error | ||
| 119 | /* Only gcc ≥ 4.7 has __builtin_va_arg_pack. */ | ||
| 120 | # if _GL_GNUC_PREREQ (4, 7) | ||
| 121 | # pragma GCC diagnostic push | ||
| 122 | # pragma GCC diagnostic ignored "-Wattributes" | ||
| 123 | _GL_ATTRIBUTE_MAYBE_UNUSED | ||
| 124 | static void | ||
| 125 | _GL_ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_COLD | ||
| 126 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 3, 4)) | ||
| 127 | _gl_inline_error (int __status, int __errnum, const char *__format, ...) | ||
| 128 | { | ||
| 129 | return error (__status, __errnum, __format, __builtin_va_arg_pack ()); | ||
| 130 | } | ||
| 131 | # pragma GCC diagnostic pop | ||
| 132 | # undef error | ||
| 133 | # define error(status, ...) \ | ||
| 134 | __gl_error_call (_gl_inline_error, status, __VA_ARGS__) | ||
| 135 | # endif | ||
| 136 | # else | ||
| 137 | # define error(status, ...) \ | ||
| 138 | __gl_error_call (error, status, __VA_ARGS__) | ||
| 139 | # endif | ||
| 140 | # endif | ||
| 141 | #endif | ||
| 142 | #if __GLIBC__ >= 2 | ||
| 143 | _GL_CXXALIASWARN (error); | ||
| 144 | #endif | ||
| 145 | |||
| 146 | /* Likewise. If FILENAME is non-NULL, include FILENAME:LINENO: in the | ||
| 147 | message. */ | ||
| 148 | #if @REPLACE_ERROR_AT_LINE@ | ||
| 149 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 150 | # undef error_at_line | ||
| 151 | # define error_at_line rpl_error_at_line | ||
| 152 | # endif | ||
| 153 | _GL_FUNCDECL_RPL (error_at_line, void, | ||
| 154 | (int __status, int __errnum, const char *__filename, | ||
| 155 | unsigned int __lineno, const char *__format, ...), | ||
| 156 | _GL_ATTRIBUTE_COLD | ||
| 157 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 5, 6))); | ||
| 158 | _GL_CXXALIAS_RPL (error_at_line, void, | ||
| 159 | (int __status, int __errnum, const char *__filename, | ||
| 160 | unsigned int __lineno, const char *__format, ...)); | ||
| 161 | # ifndef _GL_NO_INLINE_ERROR | ||
| 162 | # undef error_at_line | ||
| 163 | # define error_at_line(status, ...) \ | ||
| 164 | __gl_error_call (rpl_error_at_line, status, __VA_ARGS__) | ||
| 165 | # endif | ||
| 166 | #else | ||
| 167 | # if ! @HAVE_ERROR_AT_LINE@ | ||
| 168 | _GL_FUNCDECL_SYS (error_at_line, void, | ||
| 169 | (int __status, int __errnum, const char *__filename, | ||
| 170 | unsigned int __lineno, const char *__format, ...), | ||
| 171 | _GL_ATTRIBUTE_COLD | ||
| 172 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 5, 6))); | ||
| 173 | # endif | ||
| 174 | _GL_CXXALIAS_SYS (error_at_line, void, | ||
| 175 | (int __status, int __errnum, const char *__filename, | ||
| 176 | unsigned int __lineno, const char *__format, ...)); | ||
| 177 | # ifndef _GL_NO_INLINE_ERROR | ||
| 178 | # ifdef error_at_line | ||
| 179 | /* Only gcc ≥ 4.7 has __builtin_va_arg_pack. */ | ||
| 180 | # if _GL_GNUC_PREREQ (4, 7) | ||
| 181 | # pragma GCC diagnostic push | ||
| 182 | # pragma GCC diagnostic ignored "-Wattributes" | ||
| 183 | _GL_ATTRIBUTE_MAYBE_UNUSED | ||
| 184 | static void | ||
| 185 | _GL_ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_COLD | ||
| 186 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 5, 6)) | ||
| 187 | _gl_inline_error_at_line (int __status, int __errnum, const char *__filename, | ||
| 188 | unsigned int __lineno, const char *__format, ...) | ||
| 189 | { | ||
| 190 | return error_at_line (__status, __errnum, __filename, __lineno, __format, | ||
| 191 | __builtin_va_arg_pack ()); | ||
| 192 | } | ||
| 193 | # pragma GCC diagnostic pop | ||
| 194 | # undef error_at_line | ||
| 195 | # define error_at_line(status, ...) \ | ||
| 196 | __gl_error_call (_gl_inline_error_at_line, status, __VA_ARGS__) | ||
| 197 | # endif | ||
| 198 | # else | ||
| 199 | # define error_at_line(status, ...) \ | ||
| 200 | __gl_error_call (error_at_line, status, __VA_ARGS__) | ||
| 201 | # endif | ||
| 202 | # endif | ||
| 203 | #endif | ||
| 204 | _GL_CXXALIASWARN (error_at_line); | ||
| 205 | |||
| 206 | /* Print a message with 'vfprintf (stderr, FORMAT, ARGS)'; | ||
| 207 | if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). | ||
| 208 | If STATUS is nonzero, terminate the program with 'exit (STATUS)'. | ||
| 209 | Use the globals error_print_progname and error_message_count similarly | ||
| 210 | to error(). */ | ||
| 211 | |||
| 212 | extern void verror (int __status, int __errnum, const char *__format, | ||
| 213 | va_list __args) | ||
| 214 | _GL_ATTRIBUTE_COLD | ||
| 215 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 0)); | ||
| 216 | #ifndef _GL_NO_INLINE_ERROR | ||
| 217 | # ifndef verror | ||
| 218 | # define verror(status, ...) \ | ||
| 219 | __gl_error_call (verror, status, __VA_ARGS__) | ||
| 220 | # define GNULIB_defined_verror 1 | ||
| 221 | # endif | ||
| 222 | #endif | ||
| 223 | |||
| 224 | /* Print a message with 'vfprintf (stderr, FORMAT, ARGS)'; | ||
| 225 | if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). | ||
| 226 | If STATUS is nonzero, terminate the program with 'exit (STATUS)'. | ||
| 227 | If FNAME is not NULL, prepend the message with "FNAME:LINENO:". | ||
| 228 | Use the globals error_print_progname, error_message_count, and | ||
| 229 | error_one_per_line similarly to error_at_line(). */ | ||
| 230 | |||
| 231 | extern void verror_at_line (int __status, int __errnum, const char *__fname, | ||
| 232 | unsigned int __lineno, const char *__format, | ||
| 233 | va_list __args) | ||
| 234 | _GL_ATTRIBUTE_COLD | ||
| 235 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 5, 0)); | ||
| 236 | #ifdef _GL_NO_INLINE_ERROR | ||
| 237 | # ifndef verror_at_line | ||
| 238 | # define verror_at_line(status, ...) \ | ||
| 239 | __gl_error_call (verror_at_line, status, __VA_ARGS__) | ||
| 240 | # define GNULIB_defined_verror_at_line 1 | ||
| 241 | # endif | ||
| 242 | #endif | ||
| 243 | |||
| 244 | /* If NULL, error will flush stdout, then print on stderr the program | ||
| 245 | name, a colon and a space. Otherwise, error will call this | ||
| 246 | function without parameters instead. */ | ||
| 247 | extern void (*error_print_progname) (void); | ||
| 248 | |||
| 249 | /* This variable is incremented each time 'error' is called. */ | ||
| 250 | extern unsigned int error_message_count; | ||
| 251 | |||
| 252 | /* Sometimes we want to have at most one error per line. This | ||
| 253 | variable controls whether this mode is selected or not. */ | ||
| 254 | extern int error_one_per_line; | ||
| 255 | |||
| 256 | #ifdef __cplusplus | ||
| 257 | } | ||
| 258 | #endif | ||
| 259 | |||
| 260 | #endif /* _@GUARD_PREFIX@_ERROR_H */ | ||
| 261 | #endif /* _@GUARD_PREFIX@_ERROR_H */ | ||
