master
 1/* Specializations for error functions.
 2   Copyright (C) 2007-2025 Free Software Foundation, Inc.
 3   This file is part of the GNU C Library.
 4
 5   The GNU C Library is free software; you can redistribute it and/or
 6   modify it under the terms of the GNU Lesser General Public
 7   License as published by the Free Software Foundation; either
 8   version 2.1 of the License, or (at your option) any later version.
 9
10   The GNU C Library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with the GNU C Library; if not, see
17   <https://www.gnu.org/licenses/>.  */
18
19#ifndef	_ERROR_H
20# error "Never include <bits/error.h> directly; use <error.h> instead."
21#endif
22
23
24extern void __REDIRECT (__error_alias, (int __status, int __errnum,
25					const char *__format, ...),
26			error)
27  __attribute__ ((__format__ (__printf__, 3, 4)));
28extern void __REDIRECT (__error_noreturn, (int __status, int __errnum,
29					   const char *__format, ...),
30			error)
31  __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4)));
32
33
34/* If we know the function will never return make sure the compiler
35   realizes that, too.  */
36__extern_always_inline void
37error (int __status, int __errnum, const char *__format, ...)
38{
39  if (__builtin_constant_p (__status) && __status != 0)
40    __error_noreturn (__status, __errnum, __format, __va_arg_pack ());
41  else
42    __error_alias (__status, __errnum, __format, __va_arg_pack ());
43}
44
45
46extern void __REDIRECT (__error_at_line_alias, (int __status, int __errnum,
47						const char *__fname,
48						unsigned int __line,
49						const char *__format, ...),
50			error_at_line)
51  __attribute__ ((__format__ (__printf__, 5, 6)));
52extern void __REDIRECT (__error_at_line_noreturn, (int __status, int __errnum,
53						   const char *__fname,
54						   unsigned int __line,
55						   const char *__format,
56						   ...),
57			error_at_line)
58  __attribute__ ((__noreturn__, __format__ (__printf__, 5, 6)));
59
60
61/* If we know the function will never return make sure the compiler
62   realizes that, too.  */
63__extern_always_inline void
64error_at_line (int __status, int __errnum, const char *__fname,
65	       unsigned int __line, const char *__format, ...)
66{
67  if (__builtin_constant_p (__status) && __status != 0)
68    __error_at_line_noreturn (__status, __errnum, __fname, __line, __format,
69			      __va_arg_pack ());
70  else
71    __error_at_line_alias (__status, __errnum, __fname, __line,
72			   __format, __va_arg_pack ());
73}