My Project
programmer's documentation
bft_error.h
Go to the documentation of this file.
1 #ifndef __BFT_ERROR_H__
2 #define __BFT_ERROR_H__
3 
4 /*============================================================================
5  * Base error handling
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2019 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 #include "cs_defs.h"
31 
32 /*----------------------------------------------------------------------------*/
33 
34 /*----------------------------------------------------------------------------
35  * Standard C library headers
36  *----------------------------------------------------------------------------*/
37 
38 #include <stdarg.h>
39 
40 /*----------------------------------------------------------------------------
41  * Local headers
42  *----------------------------------------------------------------------------*/
43 
44 /*-----------------------------------------------------------------------------*/
45 
47 
48 /*============================================================================
49  * Public types
50  *============================================================================*/
51 
52 typedef void (bft_error_handler_t) (const char *const file_name,
53  const int line_num,
54  const int sys_error_code,
55  const char *const format,
56  va_list arg_ptr);
57 
58 /*============================================================================
59  * Public function prototypes
60  *============================================================================*/
61 
62 /*
63  * Calls the error handler (set by bft_error_handler_set() or default).
64  *
65  * With the default error handler, bft_print_flush() is called, an error
66  * message is output to stderr, and the current process exits with an
67  * EXIT_FAILURE code.
68  *
69  * parameters:
70  * file_name: <-- name of source file from which error handler called.
71  * line_num: <-- line of source file from which error handler called.
72  * sys_error_code: <-- error code if error in system or libc call, 0 otherwise.
73  * format: <-- format string, as printf() and family.
74  * ... : <-- variable arguments based on format string.
75  */
76 
77 #if defined(__GNUC__)
78 
79 void
80 bft_error(const char *const file_name,
81  const int line_num,
82  const int sys_error_code,
83  const char *const format,
84  ...)
85  __attribute__((format(printf, 4, 5)));
86 
87 #else
88 
89 void
90 bft_error(const char *const file_name,
91  const int line_num,
92  const int sys_error_code,
93  const char *const format,
94  ...);
95 
96 #endif
97 
98 /*
99  * Returns the error handler associated with the bft_error() function.
100  *
101  * returns:
102  * pointer to the error handler function.
103  */
104 
107 
108 /*
109  * Associates an error handler with the bft_error() function.
110  *
111  * parameters:
112  * handler: <-- pointer to the error handler function.
113  */
114 
115 void
117 
118 /*----------------------------------------------------------------------------*/
119 
121 
122 #endif /* __BFT_ERROR_H__ */
cs_defs.h
bft_error_handler_set
void bft_error_handler_set(bft_error_handler_t *const handler)
Associates an error handler with the bft_error() function.
Definition: bft_error.c:227
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
bft_error_handler_get
bft_error_handler_t * bft_error_handler_get(void)
Returns the error handler associated with the bft_error() function.
Definition: bft_error.c:215
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
bft_error
void bft_error(const char *const file_name, const int line_num, const int sys_error_code, const char *const format,...)
Calls the error handler (set by bft_error_handler_set() or default).
Definition: bft_error.c:193
bft_error_handler_t
void() bft_error_handler_t(const char *const file_name, const int line_num, const int sys_error_code, const char *const format, va_list arg_ptr)
Function pointer to opaque error handler.
Definition: bft_error.h:52