1 /* $Id$ */
2 #if !defined COMMON_H
3 #define COMMON_H
4 
5 #if defined HAVE_CONFIG_H
6 #include "config.h"
7 #endif /* HAVE_CONFIG_H */
8 
9 #include <stdio.h>
10 
11 #if defined STDC_HEADERS
12 #include <stdlib.h>
13 #include <string.h>
14 #elif defined HAVE_STRING_H
15 #include <string.h>
16 #endif /* STDC_HEADERS */
17 
18 #if !defined EXIT_SUCCESS
19 #define EXIT_SUCCESS 0
20 #define EXIT_FAILURE !0
21 #endif /* !EXIT_SUCCESS */
22 
23 #if !defined TRUE
24 #define TRUE !0
25 #define FALSE 0
26 #endif /* !TRUE */
27 
28 #if defined __cplusplus
29 #define BEGIN_C_DECLS extern "C" {
30 #define END_C_DECLS   }
31 #else
32 #define BEGIN_C_DECLS
33 #define END_C_DECLS
34 #endif /* __cplusplus */
35 
36 #if defined DEBUG
37 #define DEBUG_PRINT(...) do { fprintf(stdout, "%s:%d: ", __FILE__, __LINE__); fprintf(stdout, __VA_ARGS__); } while(0)
38 #else
39 #define DEBUG_PRINT(...)
40 #endif /* DEBUG */
41 
42 #define XCALLOC(type, num) ((type *)xcalloc((num), sizeof(type)))
43 #define XMALLOC(type, num) ((type *)xmalloc((num)*sizeof(type)))
44 #define XREALLOC(type, p, num) ((type *)xrealloc((p), (num)*sizeof(type)))
45 #define XFREE(stale) do { if (stale != NULL) { free(stale); stale = NULL; } } while(0)
46 
47 BEGIN_C_DECLS
48 
49 extern void *xcalloc(size_t num, size_t size);
50 extern void *xmalloc(size_t num);
51 extern void *xrealloc(void *p, size_t num);
52 
53 END_C_DECLS
54 
55 #endif /* !COMMON_H */
56