diff options
Diffstat (limited to 'gl/error.in.h')
| -rw-r--r-- | gl/error.in.h | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/gl/error.in.h b/gl/error.in.h new file mode 100644 index 00000000..51f8cafd --- /dev/null +++ b/gl/error.in.h | |||
| @@ -0,0 +1,216 @@ | |||
| 1 | /* Declarations for error-reporting functions. | ||
| 2 | Copyright (C) 1995-1997, 2003, 2006, 2008-2024 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@ | ||
| 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_FORMAT, | ||
| 34 | _GL_ATTRIBUTE_MAYBE_UNUSED. */ | ||
| 35 | #if !_GL_CONFIG_H_INCLUDED | ||
| 36 | #error "Please include config.h first." | ||
| 37 | #endif | ||
| 38 | |||
| 39 | /* Get 'unreachable'. */ | ||
| 40 | #include <stddef.h> | ||
| 41 | |||
| 42 | /* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM. */ | ||
| 43 | #include <stdio.h> | ||
| 44 | |||
| 45 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ | ||
| 46 | |||
| 47 | #if GNULIB_VFPRINTF_POSIX | ||
| 48 | # define _GL_ATTRIBUTE_SPEC_PRINTF_ERROR _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD | ||
| 49 | #else | ||
| 50 | # define _GL_ATTRIBUTE_SPEC_PRINTF_ERROR _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM | ||
| 51 | #endif | ||
| 52 | |||
| 53 | /* Helper macro for supporting the compiler's control flow analysis better. | ||
| 54 | It evaluates its arguments only once. | ||
| 55 | Test case: Compile copy-file.c with "gcc -Wimplicit-fallthrough". */ | ||
| 56 | #if defined __GNUC__ || defined __clang__ | ||
| 57 | /* Use 'unreachable' to tell the compiler when the function call does not | ||
| 58 | return. */ | ||
| 59 | # define __gl_error_call1(function, status, ...) \ | ||
| 60 | ((function) (status, __VA_ARGS__), \ | ||
| 61 | (status) != 0 ? unreachable () : (void) 0) | ||
| 62 | /* If STATUS is a not a constant, the function call may or may not return; | ||
| 63 | therefore -Wimplicit-fallthrough will produce a warning. Use a compound | ||
| 64 | statement in order to evaluate STATUS only once. | ||
| 65 | If STATUS is a constant, we don't use a compound statement, because that | ||
| 66 | would trigger a -Wimplicit-fallthrough warning even when STATUS is != 0, | ||
| 67 | when not optimizing. This causes STATUS to be evaluated twice, but | ||
| 68 | that's OK since it does not have side effects. */ | ||
| 69 | # define __gl_error_call(function, status, ...) \ | ||
| 70 | (__builtin_constant_p (status) \ | ||
| 71 | ? __gl_error_call1 (function, status, __VA_ARGS__) \ | ||
| 72 | : __extension__ \ | ||
| 73 | ({ \ | ||
| 74 | int const __errstatus = status; \ | ||
| 75 | __gl_error_call1 (function, __errstatus, __VA_ARGS__); \ | ||
| 76 | })) | ||
| 77 | #else | ||
| 78 | # define __gl_error_call(function, status, ...) \ | ||
| 79 | (function) (status, __VA_ARGS__) | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #ifdef __cplusplus | ||
| 83 | extern "C" { | ||
| 84 | #endif | ||
| 85 | |||
| 86 | /* Print a message with 'fprintf (stderr, FORMAT, ...)'; | ||
| 87 | if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). | ||
| 88 | If STATUS is nonzero, terminate the program with 'exit (STATUS)'. */ | ||
| 89 | #if @REPLACE_ERROR@ | ||
| 90 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 91 | # undef error | ||
| 92 | # define error rpl_error | ||
| 93 | # endif | ||
| 94 | _GL_FUNCDECL_RPL (error, void, | ||
| 95 | (int __status, int __errnum, const char *__format, ...) | ||
| 96 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 3, 4))); | ||
| 97 | _GL_CXXALIAS_RPL (error, void, | ||
| 98 | (int __status, int __errnum, const char *__format, ...)); | ||
| 99 | # ifndef _GL_NO_INLINE_ERROR | ||
| 100 | # undef error | ||
| 101 | # define error(status, ...) \ | ||
| 102 | __gl_error_call (rpl_error, status, __VA_ARGS__) | ||
| 103 | # endif | ||
| 104 | #else | ||
| 105 | # if ! @HAVE_ERROR@ | ||
| 106 | _GL_FUNCDECL_SYS (error, void, | ||
| 107 | (int __status, int __errnum, const char *__format, ...) | ||
| 108 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 3, 4))); | ||
| 109 | # endif | ||
| 110 | _GL_CXXALIAS_SYS (error, void, | ||
| 111 | (int __status, int __errnum, const char *__format, ...)); | ||
| 112 | # ifndef _GL_NO_INLINE_ERROR | ||
| 113 | # ifdef error | ||
| 114 | /* Only gcc ≥ 4.7 has __builtin_va_arg_pack. */ | ||
| 115 | # if _GL_GNUC_PREREQ (4, 7) | ||
| 116 | # pragma GCC diagnostic push | ||
| 117 | # pragma GCC diagnostic ignored "-Wattributes" | ||
| 118 | _GL_ATTRIBUTE_MAYBE_UNUSED | ||
| 119 | static void | ||
| 120 | _GL_ATTRIBUTE_ALWAYS_INLINE | ||
| 121 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 3, 4)) | ||
| 122 | _gl_inline_error (int __status, int __errnum, const char *__format, ...) | ||
| 123 | { | ||
| 124 | return error (__status, __errnum, __format, __builtin_va_arg_pack ()); | ||
| 125 | } | ||
| 126 | # pragma GCC diagnostic pop | ||
| 127 | # undef error | ||
| 128 | # define error(status, ...) \ | ||
| 129 | __gl_error_call (_gl_inline_error, status, __VA_ARGS__) | ||
| 130 | # endif | ||
| 131 | # else | ||
| 132 | # define error(status, ...) \ | ||
| 133 | __gl_error_call (error, status, __VA_ARGS__) | ||
| 134 | # endif | ||
| 135 | # endif | ||
| 136 | #endif | ||
| 137 | #if __GLIBC__ >= 2 | ||
| 138 | _GL_CXXALIASWARN (error); | ||
| 139 | #endif | ||
| 140 | |||
| 141 | /* Likewise. If FILENAME is non-NULL, include FILENAME:LINENO: in the | ||
| 142 | message. */ | ||
| 143 | #if @REPLACE_ERROR_AT_LINE@ | ||
| 144 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 145 | # undef error_at_line | ||
| 146 | # define error_at_line rpl_error_at_line | ||
| 147 | # endif | ||
| 148 | _GL_FUNCDECL_RPL (error_at_line, void, | ||
| 149 | (int __status, int __errnum, const char *__filename, | ||
| 150 | unsigned int __lineno, const char *__format, ...) | ||
| 151 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 5, 6))); | ||
| 152 | _GL_CXXALIAS_RPL (error_at_line, void, | ||
| 153 | (int __status, int __errnum, const char *__filename, | ||
| 154 | unsigned int __lineno, const char *__format, ...)); | ||
| 155 | # ifndef _GL_NO_INLINE_ERROR | ||
| 156 | # undef error_at_line | ||
| 157 | # define error_at_line(status, ...) \ | ||
| 158 | __gl_error_call (rpl_error_at_line, status, __VA_ARGS__) | ||
| 159 | # endif | ||
| 160 | #else | ||
| 161 | # if ! @HAVE_ERROR_AT_LINE@ | ||
| 162 | _GL_FUNCDECL_SYS (error_at_line, void, | ||
| 163 | (int __status, int __errnum, const char *__filename, | ||
| 164 | unsigned int __lineno, const char *__format, ...) | ||
| 165 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 5, 6))); | ||
| 166 | # endif | ||
| 167 | _GL_CXXALIAS_SYS (error_at_line, void, | ||
| 168 | (int __status, int __errnum, const char *__filename, | ||
| 169 | unsigned int __lineno, const char *__format, ...)); | ||
| 170 | # ifndef _GL_NO_INLINE_ERROR | ||
| 171 | # ifdef error_at_line | ||
| 172 | /* Only gcc ≥ 4.7 has __builtin_va_arg_pack. */ | ||
| 173 | # if _GL_GNUC_PREREQ (4, 7) | ||
| 174 | # pragma GCC diagnostic push | ||
| 175 | # pragma GCC diagnostic ignored "-Wattributes" | ||
| 176 | _GL_ATTRIBUTE_MAYBE_UNUSED | ||
| 177 | static void | ||
| 178 | _GL_ATTRIBUTE_ALWAYS_INLINE | ||
| 179 | _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 5, 6)) | ||
| 180 | _gl_inline_error_at_line (int __status, int __errnum, const char *__filename, | ||
| 181 | unsigned int __lineno, const char *__format, ...) | ||
| 182 | { | ||
| 183 | return error_at_line (__status, __errnum, __filename, __lineno, __format, | ||
| 184 | __builtin_va_arg_pack ()); | ||
| 185 | } | ||
| 186 | # pragma GCC diagnostic pop | ||
| 187 | # undef error_at_line | ||
| 188 | # define error_at_line(status, ...) \ | ||
| 189 | __gl_error_call (_gl_inline_error_at_line, status, __VA_ARGS__) | ||
| 190 | # endif | ||
| 191 | # else | ||
| 192 | # define error_at_line(status, ...) \ | ||
| 193 | __gl_error_call (error_at_line, status, __VA_ARGS__) | ||
| 194 | # endif | ||
| 195 | # endif | ||
| 196 | #endif | ||
| 197 | _GL_CXXALIASWARN (error_at_line); | ||
| 198 | |||
| 199 | /* If NULL, error will flush stdout, then print on stderr the program | ||
| 200 | name, a colon and a space. Otherwise, error will call this | ||
| 201 | function without parameters instead. */ | ||
| 202 | extern void (*error_print_progname) (void); | ||
| 203 | |||
| 204 | /* This variable is incremented each time 'error' is called. */ | ||
| 205 | extern unsigned int error_message_count; | ||
| 206 | |||
| 207 | /* Sometimes we want to have at most one error per line. This | ||
| 208 | variable controls whether this mode is selected or not. */ | ||
| 209 | extern int error_one_per_line; | ||
| 210 | |||
| 211 | #ifdef __cplusplus | ||
| 212 | } | ||
| 213 | #endif | ||
| 214 | |||
| 215 | #endif /* _@GUARD_PREFIX@_ERROR_H */ | ||
| 216 | #endif /* _@GUARD_PREFIX@_ERROR_H */ | ||
