00001
00016 #ifndef _EPDEFS_H_
00017 #define _EPDEFS_H_
00018
00019 #include <stdlib.h>
00020
00021
00022 #define boolean_t int
00023 #define _false (0)
00024 #define _true (!_false) 00025 00026 00027
00028 #define _sfalse "<false>"
00029 #define _strue "<true>"
00030 #define _BOOL_TO_STRING(bool) (!(bool)?_sfalse:_strue)
00031
00032 #define ushort unsigned short
00033 #define uint unsigned int
00034 #define ulong unsigned long
00035
00036
00037
00038
00046 #define _DEBUG(arg...)
00047 #define _DEBUG2(arg...)
00048 #define _DEBUG3(arg...)
00049 #define _DEBUG4(arg...)
00050 #define _ABORT(arg...) abort()
00051 #define _EXIT(arg...) exit(-1)
00052 #define _NDEBUG(args...) args
00053
00054 #ifdef __GNUC__
00055 # undef _ABORT
00056 # undef _EXIT
00057
00058 #ifdef DEBUG
00059 # undef _NDEBUG
00060 # define _NDEBUG(args...)
00061
00062 # undef _DEBUG
00063 # define _DEBUG(msg, args...) \
00064 fprintf(stdout, "* %-15s::%-15s:: "msg"\n", __FILE__, __FUNCTION__, \
00065 ##args)
00066
00067 # if DEBUG > 1
00068 # undef _DEBUG2
00069 # define _DEBUG2(msg, args...) _DEBUG(msg, args)
00070 # endif
00071
00072 # if DEBUG > 2
00073 # undef _DEBUG3
00074 # define _DEBUG3(msg, args...) _DEBUG(" "msg, args)
00075 # endif
00076
00077 # if DEBUG > 3
00078 # undef _DEBUG4
00079 # define _DEBUG4(msg, args...) _DEBUG(" "msg, args)
00080 # endif
00081 #endif
00082
00083 #define _ABORT(msg, args...) \
00084 fprintf(stderr, "*- ABORT -* %-15s::%-15s:: "msg"\n", __FILE__, \
00085 __FUNCTION__, ## args); \
00086 abort()
00087
00088 #define _EXIT(msg, args...) \
00089 fprintf(stderr, "*- EXIT -* %-15s::%-15s:: "msg"\n", __FILE__, \
00090 __FUNCTION__, ## args); \
00091 exit(-1)
00092
00093
00094 00095 00096 00097 00098
00099 #ifdef DEBUG
00100 # define _FATAL_ERROR(retval, msg, args...) \
00101 fprintf(stderr, "*- FATAL ERROR -* %-15s::%-15s(line #%d):: "msg"\n", \
00102 __FILE__, __FUNCTION__, __LINE__, ## args); \
00103 abort()
00104 #else
00105 # define _FATAL_ERROR(retval, msg, args...) \
00106 fprintf(stderr, "*- FATAL ERROR -* %-15s::%-15s(line #%d):: "msg"\n", \
00107 __FILE__, __FUNCTION__, __LINE__, ## args); \
00108 exit(retval)
00109 #endif
00110
00111 #endif
00112
00113 00114
00115 #define _IF_TRUE_RETURN(test, errcode, retval) \
00116 if(test) \
00117 { return(retval); }
00118
00119 00120
00121 #define _RETURN(retval) return(retval)
00122
00123
00124
00125 #define _XMALLOC(len) \
00126 ({ \
00127 void *__ptr; \
00128 \
00129 if((__ptr = malloc(len)) == NULL) \
00130 { _FATAL_ERROR(1, "%s", "Echec d'allocation de mémoire"); } \
00131 \
00132 __ptr; \
00133 })
00134
00135 #define _XDUP(type, value) \
00136 ({ \
00137 type *__x =(type *) _XMALLOC(sizeof(type)); \
00138 (type *) memcpy((void *)__x, (const void *)&(value), sizeof(type)); \
00139 })
00140
00141 #define _XSTRDUP(value) \
00142 ({ \
00143 size_t __len; \
00144 char *__x; \
00145 \
00146 if(value == NULL) \
00147 { __x = NULL; } \
00148 else \
00149 { \
00150 __len = strlen(value)+1; \
00151 __x =(char *) _XMALLOC(__len); \
00152 memcpy((void *)__x, (const void *)(value), __len); \
00153 }; \
00154 \
00155 __x; \
00156 })
00157
00158 #define _XFREE(ptr) \
00159 ({ \
00160 if(ptr != NULL) \
00161 { free(ptr); (ptr) = NULL; } \
00162 }) \
00163
00164
00166 00167 00168 00169
00170 00171 00172 00173 00174 00175 00176 00177
00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189
00190 00191 00192 00193
00194
00195
00196
00197 #endif
00198