Preparation for adesklets 0.4.12 (bis repetita)
[adesklets.git] / src / error.h
blob78d8945b0499b1bf6f60e278ee87c715e1e3b912
1 /*--- error.h ------------------------------------------------------------------
2 Copyright (C) 2004, 2005 Sylvain Fourmanoit <syfou@users.sourceforge.net>
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to
6 deal in the Software without restriction, including without limitation the
7 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 sell copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies of the Software and its documentation and acknowledgment shall be
13 given in the documentation and software packages that this Software was
14 used.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 ------------------------------------------------------------------------------*/
23 /* Wrapper around system error functions */
25 /*----------------------------------------------------------------------------*/
26 #ifndef HAVE_ERROR_H
27 #define HAVE_ERROR_H
29 #ifndef HAVE_CONFIG_H
30 #error Autogenerated config.h should be used.
31 #endif
33 /*----------------------------------------------------------------------------*/
34 #include "config.h" /* Autoconf header */
36 #ifdef HAVE_ERRNO_H
37 #include <errno.h> /* C includes */
38 #endif
40 /*----------------------------------------------------------------------------*/
41 extern int errno_bis;
43 /*----------------------------------------------------------------------------*/
44 /* Error related management
46 #define TRY_CATCH(x)\
47 do {\
48 errno=0;\
49 do { x; } while(0);\
50 if(errno) { errno_bis=errno; return 0;}\
51 } while(0)
53 /* Whenever TRY is going to be used in a function,
54 TRY_RESET should be invoked before. */
55 #define TRY(x)\
56 do {\
57 errno=0;\
58 do { x; } while(0);\
59 if(errno) errno_bis=errno;\
60 } while(0)
62 #define TRY_SUCCESS (errno_bis==0)
63 #define TRY_RESET errno_bis=0
65 /*----------------------------------------------------------------------------*/
66 /* Debugging related.
67 I know, I know, variadic macros are ISO99 C, not ANSI...
69 #ifdef DEBUG
70 #ifdef HAVE_STDIO_H
71 #include <stdio.h>
72 #endif
73 #ifdef HAVE_STDARG_H
74 #include <stdarg.h>
75 #endif
76 #ifdef HAVE_STDLIB_H
77 #include <stdlib.h>
78 #endif
79 #ifdef HAVE_SYS_TYPES_H
80 #include <sys/types.h>
81 #endif
82 #ifdef HAVE_UNISTD_H
83 #include <unistd.h>
84 #endif
85 void debug_init(void);
86 int debug(const char *, ...);
87 int vdebug(const char *, va_list);
88 int debug_on_stderr(void);
89 #else
90 #define debug( ... )
91 #endif
93 /* Now, make sure we have strerror() defined
95 #ifdef HAVE_STRING_H
96 #include <string.h>
97 #else
98 #ifdef HAVE_ERRNO_H
99 #define strerror(errnum) sys_errlist[errnum]
100 #else
101 #define strerror(errnum) NULL
102 #endif
103 #endif
105 /*----------------------------------------------------------------------------*/
106 #endif