(root)/
tar-1.35/
gnu/
error.in.h
       1  /* Declarations for error-reporting functions.
       2     Copyright (C) 1995-1997, 2003, 2006, 2008-2023 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  #ifdef __GNUC__
      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       : ({ \
      73           int const __errstatus = status; \
      74           __gl_error_call1 (function, __errstatus, __VA_ARGS__); \
      75         }))
      76  #else
      77  # define __gl_error_call(function, status, ...) \
      78      (function) (status, __VA_ARGS__)
      79  #endif
      80  
      81  #ifdef __cplusplus
      82  extern "C" {
      83  #endif
      84  
      85  /* Print a message with 'fprintf (stderr, FORMAT, ...)';
      86     if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
      87     If STATUS is nonzero, terminate the program with 'exit (STATUS)'.  */
      88  #if @REPLACE_ERROR@
      89  # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
      90  #  undef error
      91  #  define error rpl_error
      92  # endif
      93  _GL_FUNCDECL_RPL (error, void,
      94                    (int __status, int __errnum, const char *__format, ...)
      95                    _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 3, 4)));
      96  _GL_CXXALIAS_RPL (error, void,
      97                    (int __status, int __errnum, const char *__format, ...));
      98  # ifndef _GL_NO_INLINE_ERROR
      99  #  undef error
     100  #  define error(status, ...) \
     101       __gl_error_call (rpl_error, status, __VA_ARGS__)
     102  # endif
     103  #else
     104  # if ! @HAVE_ERROR@
     105  _GL_FUNCDECL_SYS (error, void,
     106                    (int __status, int __errnum, const char *__format, ...)
     107                    _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 3, 4)));
     108  # endif
     109  _GL_CXXALIAS_SYS (error, void,
     110                    (int __status, int __errnum, const char *__format, ...));
     111  # ifndef _GL_NO_INLINE_ERROR
     112  #  ifdef error
     113  /* Only gcc ≥ 4.7 has __builtin_va_arg_pack.  */
     114  #   if _GL_GNUC_PREREQ (4, 7)
     115  #    pragma GCC diagnostic push
     116  #    pragma GCC diagnostic ignored "-Wattributes"
     117  _GL_ATTRIBUTE_MAYBE_UNUSED
     118  static void
     119  _GL_ATTRIBUTE_ALWAYS_INLINE
     120  _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 3, 4))
     121  _gl_inline_error (int __status, int __errnum, const char *__format, ...)
     122  {
     123    return error (__status, __errnum, __format, __builtin_va_arg_pack ());
     124  }
     125  #    pragma GCC diagnostic pop
     126  #    undef error
     127  #    define error(status, ...) \
     128         __gl_error_call (_gl_inline_error, status, __VA_ARGS__)
     129  #   endif
     130  #  else
     131  #   define error(status, ...) \
     132        __gl_error_call (error, status, __VA_ARGS__)
     133  #  endif
     134  # endif
     135  #endif
     136  #if __GLIBC__ >= 2
     137  _GL_CXXALIASWARN (error);
     138  #endif
     139  
     140  /* Likewise.  If FILENAME is non-NULL, include FILENAME:LINENO: in the
     141     message.  */
     142  #if @REPLACE_ERROR_AT_LINE@
     143  # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
     144  #  undef error_at_line
     145  #  define error_at_line rpl_error_at_line
     146  # endif
     147  _GL_FUNCDECL_RPL (error_at_line, void,
     148                    (int __status, int __errnum, const char *__filename,
     149                     unsigned int __lineno, const char *__format, ...)
     150                    _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 5, 6)));
     151  _GL_CXXALIAS_RPL (error_at_line, void,
     152                    (int __status, int __errnum, const char *__filename,
     153                     unsigned int __lineno, const char *__format, ...));
     154  # ifndef _GL_NO_INLINE_ERROR
     155  #  undef error_at_line
     156  #  define error_at_line(status, ...) \
     157       __gl_error_call (rpl_error_at_line, status, __VA_ARGS__)
     158  # endif
     159  #else
     160  # if ! @HAVE_ERROR_AT_LINE@
     161  _GL_FUNCDECL_SYS (error_at_line, void,
     162                    (int __status, int __errnum, const char *__filename,
     163                     unsigned int __lineno, const char *__format, ...)
     164                    _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 5, 6)));
     165  # endif
     166  _GL_CXXALIAS_SYS (error_at_line, void,
     167                    (int __status, int __errnum, const char *__filename,
     168                     unsigned int __lineno, const char *__format, ...));
     169  # ifndef _GL_NO_INLINE_ERROR
     170  #  ifdef error_at_line
     171  /* Only gcc ≥ 4.7 has __builtin_va_arg_pack.  */
     172  #   if _GL_GNUC_PREREQ (4, 7)
     173  #    pragma GCC diagnostic push
     174  #    pragma GCC diagnostic ignored "-Wattributes"
     175  _GL_ATTRIBUTE_MAYBE_UNUSED
     176  static void
     177  _GL_ATTRIBUTE_ALWAYS_INLINE
     178  _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_ERROR, 5, 6))
     179  _gl_inline_error_at_line (int __status, int __errnum, const char *__filename,
     180                            unsigned int __lineno, const char *__format, ...)
     181  {
     182    return error_at_line (__status, __errnum, __filename, __lineno, __format,
     183                          __builtin_va_arg_pack ());
     184  }
     185  #    pragma GCC diagnostic pop
     186  #    undef error_at_line
     187  #    define error_at_line(status, ...) \
     188         __gl_error_call (_gl_inline_error_at_line, status, __VA_ARGS__)
     189  #   endif
     190  #  else
     191  #   define error_at_line(status, ...) \
     192        __gl_error_call (error_at_line, status, __VA_ARGS__)
     193  #  endif
     194  # endif
     195  #endif
     196  _GL_CXXALIASWARN (error_at_line);
     197  
     198  /* If NULL, error will flush stdout, then print on stderr the program
     199     name, a colon and a space.  Otherwise, error will call this
     200     function without parameters instead.  */
     201  extern void (*error_print_progname) (void);
     202  
     203  /* This variable is incremented each time 'error' is called.  */
     204  extern unsigned int error_message_count;
     205  
     206  /* Sometimes we want to have at most one error per line.  This
     207     variable controls whether this mode is selected or not.  */
     208  extern int error_one_per_line;
     209  
     210  #ifdef __cplusplus
     211  }
     212  #endif
     213  
     214  #endif /* _@GUARD_PREFIX@_ERROR_H */
     215  #endif /* _@GUARD_PREFIX@_ERROR_H */