error.h 3.2 KB

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