Code_Saturne
CFD tool
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-2012 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 /* Standard C library headers */
31 
32 #include <stdarg.h>
33 
34 /* BFT library headers */
35 
36 /*-----------------------------------------------------------------------------*/
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #if 0
41 } /* Fake brace to force Emacs auto-indentation back to column 0 */
42 #endif
43 #endif /* __cplusplus */
44 
45 /*============================================================================
46  * Public types
47  *============================================================================*/
48 
49 typedef void (bft_error_handler_t) (const char *const file_name,
50  const int line_num,
51  const int sys_error_code,
52  const char *const format,
53  va_list arg_ptr);
54 
55 /*============================================================================
56  * Public function prototypes
57  *============================================================================*/
58 
59 /*
60  * Calls the error handler (set by bft_error_handler_set() or default).
61  *
62  * With the default error handler, bft_print_flush() is called, an error
63  * message is output to stderr, and the current process exits with an
64  * EXIT_FAILURE code.
65  *
66  * parameters:
67  * file_name: <-- name of source file from which error handler called.
68  * line_num: <-- line of source file from which error handler called.
69  * sys_error_code: <-- error code if error in system or libc call, 0 otherwise.
70  * format: <-- format string, as printf() and family.
71  * ... : <-- variable arguments based on format string.
72  */
73 
74 #if defined(__GNUC__)
75 
76 void
77 bft_error(const char *const file_name,
78  const int line_num,
79  const int sys_error_code,
80  const char *const format,
81  ...)
82  __attribute__((format(printf, 4, 5)));
83 
84 #else
85 
86 void
87 bft_error(const char *const file_name,
88  const int line_num,
89  const int sys_error_code,
90  const char *const format,
91  ...);
92 
93 #endif
94 
95 /*
96  * Returns the error handler associated with the bft_error() function.
97  *
98  * returns:
99  * pointer to the error handler function.
100  */
101 
104 
105 /*
106  * Associates an error handler with the bft_error() function.
107  *
108  * parameters:
109  * handler: <-- pointer to the error handler function.
110  */
111 
112 void
114 
115 /*----------------------------------------------------------------------------*/
116 
117 #ifdef __cplusplus
118 }
119 #endif /* __cplusplus */
120 
121 #endif /* __BFT_ERROR_H__ */
void bft_error_handler_set(bft_error_handler_t *const handler)
Associates an error handler with the bft_error() function.
Definition: bft_error.c:235
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:49
bft_error_handler_t * bft_error_handler_get(void)
Returns the error handler associated with the bft_error() function.
Definition: bft_error.c:223
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:201