(root)/
strace-6.5/
src/
error_prints.h
       1  /*
       2   * This file contains error printing functions.
       3   * These functions can be used by various binaries included in the strace
       4   * package.  Variable 'program_invocation_name' and function 'die()'
       5   * have to be defined globally.
       6   *
       7   * Copyright (c) 2001-2021 The strace developers.
       8   * All rights reserved.
       9   *
      10   * SPDX-License-Identifier: LGPL-2.1-or-later
      11   */
      12  
      13  #ifndef STRACE_ERROR_PRINTS_H
      14  # define STRACE_ERROR_PRINTS_H
      15  
      16  # include <stdbool.h>
      17  
      18  # include "gcc_compat.h"
      19  
      20  extern bool debug_flag;
      21  
      22  void die(void) ATTRIBUTE_NORETURN;
      23  
      24  void error_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
      25  void perror_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
      26  void perror_msg_and_die(const char *fmt, ...)
      27  	ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
      28  void error_msg_and_help(const char *fmt, ...)
      29  	ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
      30  void error_msg_and_die(const char *fmt, ...)
      31  	ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
      32  
      33  /* Wrappers for if (debug_flag) error_msg(...) */
      34  # define debug_msg(...) \
      35  	do { \
      36  		if (debug_flag) \
      37  			error_msg(__VA_ARGS__); \
      38  	} while (0)
      39  # define debug_perror_msg(...) \
      40  	do { \
      41  		if (debug_flag) \
      42  			perror_msg(__VA_ARGS__); \
      43  	} while (0)
      44  
      45  /* Simple wrappers for providing function name in error messages */
      46  # define error_func_msg(fmt_, ...) \
      47  	error_msg("%s: " fmt_,  __func__, ##__VA_ARGS__)
      48  # define perror_func_msg(fmt_, ...) \
      49  	perror_msg("%s: " fmt_, __func__, ##__VA_ARGS__)
      50  # define debug_func_msg(fmt_, ...) \
      51  	debug_msg("%s: " fmt_, __func__, ##__VA_ARGS__)
      52  # define debug_func_perror_msg(fmt_, ...) \
      53  	debug_perror_msg("%s: " fmt_, __func__, ##__VA_ARGS__)
      54  # define error_func_msg_and_die(fmt_, ...) \
      55  	error_msg_and_die("%s: " fmt_, __func__, ##__VA_ARGS__)
      56  # define perror_func_msg_and_die(fmt_, ...) \
      57  	perror_msg_and_die("%s: " fmt_, __func__, ##__VA_ARGS__)
      58  
      59  #endif /* !STRACE_ERROR_PRINTS_H */