JabberWerxC  2015.1.1
basics.h
Go to the documentation of this file.
1 
13 #ifndef JABBERWERX_BASICS_H
14 #define JABBERWERX_BASICS_H
15 
16 #include <stdbool.h>
17 #include <stdint.h>
18 #include <stddef.h>
19 
20 
25 #if defined(_WIN32) || defined(_WIN64)
26 # ifdef jabberwerx_EXPORTS
27 # define JABBERWERX_API __declspec(dllexport)
28 # else
29 # define JABBERWERX_API __declspec(dllimport)
30 # endif
31 #else
32 # define JABBERWERX_API
33 #endif
34 
35 #ifndef UNUSED_PARAM
36 
41 # define UNUSED_PARAM(p) ((void)&(p))
42 #endif // UNUSED_PARAM
43 
44 #ifndef __GNUC__
45 
46 # define __attribute__(x)
47 #endif // __GNUC__
48 
55 #define PRAGMA(x) _Pragma(#x)
56 
57 /*
58  * Temporarily disable compiler warnings, if possible (>=gcc-4.6).
59  *
60  * In some cases (particularly within macros), certain compiler warnings are
61  * unavoidable. In order to allow these warnings to be treated as errors in
62  * most cases, these macros will disable particular warnings only during
63  * specific points in the compilation.
64  */
65 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
66 # define GCC_BEGIN_IGNORED_WARNING(x) \
67  _Pragma("GCC diagnostic push"); \
68  PRAGMA(GCC diagnostic ignored #x)
69 # define GCC_END_IGNORED_WARNING(x) \
70  _Pragma("GCC diagnostic pop")
71 #else
72 
73 # define GCC_BEGIN_IGNORED_WARNING(x)
74 
75 # define GCC_END_IGNORED_WARNING(x)
76 #endif // __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
77 
78 /*
79  * Macros for calculating standard string lengths.
80  *
81  * FOO_MAX_WIDTH is at least as wide as the base10 string version of the largest
82  * integer value of the relevant type. A buffer of size FOO_MAX_WIDTH will be
83  * large enough to sprintf a variable of the relevant type (including the
84  * terminating NULL).
85  */
88 #define BASE10_WIDTH2(s) sizeof(#s)
89 
90 #define BASE10_WIDTH(s) BASE10_WIDTH2(s)
91 
93 #define UINT64_MAX_WIDTH BASE10_WIDTH(UINT64_MAX)
94 
96 #define UINT32_MAX_WIDTH BASE10_WIDTH(UINT32_MAX)
97 
106 #define JABBERWERX_ERROR(err, errcode) \
107  GCC_BEGIN_IGNORED_WARNING(-Waddress) \
108  if ((err) != NULL) \
109  { \
110  (err)->code = (errcode); \
111  (err)->message = jw_err_message((errcode)); \
112  (err)->function = __func__; \
113  (err)->file = __FILE__; \
114  (err)->line = __LINE__; \
115  } \
116  GCC_END_IGNORED_WARNING(-Waddress)
117 
118 
122 typedef enum
123 {
149 } jw_errcode;
150 
157 typedef struct
158 {
162  const char *message;
165  const char *function;
167  const char *file;
169  unsigned long line;
170 } jw_err;
171 
172 
173 #ifdef __cplusplus
174 extern "C"
175 {
176 #endif
177 
184 JABBERWERX_API const char * jw_err_message(jw_errcode code);
185 
194 JABBERWERX_API const char * jw_version(bool full);
195 
211 
219 
220 #ifdef __cplusplus
221 }
222 #endif
223 
224 #endif /* JABBERWERX_BASICS_H */
JABBERWERX_API const char * jw_err_message(jw_errcode code)
JABBERWERX_API void jw_global_cleanup()
#define JABBERWERX_API
Definition: basics.h:32
Definition: basics.h:135
jw_errcode
Definition: basics.h:122
Definition: basics.h:141
JABBERWERX_API const char * jw_version(bool full)
const char * message
Definition: basics.h:162
Definition: basics.h:127
Definition: basics.h:145
Definition: basics.h:131
Definition: basics.h:137
const char * file
Definition: basics.h:167
JABBERWERX_API bool jw_global_init(jw_err *err)
Definition: basics.h:143
Definition: basics.h:157
Definition: basics.h:139
Definition: basics.h:148
Definition: basics.h:129
jw_errcode code
Definition: basics.h:160
Definition: basics.h:133
unsigned long line
Definition: basics.h:169
Definition: basics.h:125