error.h 2.71 KB
Newer Older
1
2
#ifndef ERROR_H
#define ERROR_H
Uwe Schulzweida's avatar
Uwe Schulzweida committed
3

Thomas Jahns's avatar
Thomas Jahns committed
4
5
6
#include <stdarg.h>
#include <stdlib.h>

7
8
9
10
#ifndef  WITH_CALLER_NAME
#define  WITH_CALLER_NAME
#endif

11
12
13
14
#ifdef __cplusplus
extern "C" {
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
15
16
17
18
extern int _ExitOnError;  /* If set to 1, exit on error (default 1)       */
extern int _Verbose;      /* If set to 1, errors are reported (default 1) */
extern int _Debug;        /* If set to 1, debuggig (default 0)            */

19
20
21
void SysError_(const char *caller, const char *fmt, ...);
void    Error_(const char *caller, const char *fmt, ...);
void  Warning_(const char *caller, const char *fmt, ...);
22
23
/* delegate used by Warning_ unless mode is PIO */
void cdiWarning(const char *caller, const char *fmt, va_list ap);
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
void  Message_(const char *caller, const char *fmt, ...);

#if  defined  WITH_CALLER_NAME
#  define  SysError(...)  SysError_(__func__, __VA_ARGS__)
#  define    Errorc(...)     Error_(  caller, __VA_ARGS__)
#  define     Error(...)     Error_(__func__, __VA_ARGS__)
#  define   Warning(...)   Warning_(__func__, __VA_ARGS__)
#  define  Messagec(...)   Message_(  caller, __VA_ARGS__)
#  define   Message(...)   Message_(__func__, __VA_ARGS__)
#else
#  define  SysError(...)  SysError_((void *), __VA_ARGS__)
#  define    Errorc(...)     Error_((void *), __VA_ARGS__)
#  define     Error(...)     Error_((void *), __VA_ARGS__)
#  define   Warning(...)   Warning_((void *), __VA_ARGS__)
#  define  Messagec(...)   Message_((void *), __VA_ARGS__)
#  define   Message(...)   Message_((void *), __VA_ARGS__)
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* If we're not using GNU C, elide __attribute__ */
#ifndef __GNUC__
#  define  __attribute__(x)  /*NOTHING*/
#endif

void cdiAbortC(const char *caller, const char *filename,
               const char *functionname, int line,
               const char *errorString, ... )
  __attribute__((noreturn));
#define xabortC(caller, ...)                                    \
  cdiAbortC(caller, __FILE__, __func__, __LINE__, __VA_ARGS__ )
#define xabort(...)                                             \
  cdiAbortC(NULL, __FILE__, __func__, __LINE__, __VA_ARGS__ )
#define cdiAbort(file, func, line, ...)                 \
  cdiAbortC(NULL, (file), (func), (line), __VA_ARGS__)

#define xassert(arg) do {                       \
    if ((arg)) { } else {                       \
60
      xabort("assertion `" #arg "` failed");}   \
61
62
  } while(0)

Thomas Jahns's avatar
Thomas Jahns committed
63
64
65
66
67
68
void
cdiAbortC_serial(const char *caller, const char *filename,
                 const char *functionname, int line,
                 const char *errorString, va_list ap)
  __attribute__((noreturn));

69
70
71
72
#if defined (__cplusplus)
}
#endif

73
#endif  /* ERROR_H */
74
75
76
77
78
79
80
81
82
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */