[go: up one dir, main page]

Menu

[d23328]: / src / flom_defines.h  Maximize  Restore  History

Download this file

297 lines (226 with data), 6.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
* Copyright (c) 2013-2016, Christian Ferrari <tiian@users.sourceforge.net>
* All rights reserved.
*
* This file is part of FLoM.
*
* FLoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* FLoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FLoM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FLOM_DEFINES_H
# define FLOM_DEFINES_H
#include <config.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif /* HAVE_STDLIB_H */
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif /* HAVE_STDINT_H */
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#ifdef HAVE_TIME_H
# include <time.h>
#endif /* HAVE_TIME_H */
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* HAVE_UNISTD_H */
/***********************************************************************
* *
* Exception macros *
* *
***********************************************************************/
#ifndef TRY
#define TRY
#endif /* TRY */
#ifndef CATCH
#define CATCH ExcpHand:
#endif /* CATCH */
#ifndef THROW
#define THROW(e) { excp = e; goto ExcpHand; }
#endif /* THROW */
#ifndef STRORNULL
/**
* STRing OR NULL:
* it can be used to print C strings even if they could be NULL; if passed
* string pointer is NULL, it returns a pointer to @ref FLOM_NULL_STRING
*/
# define STRORNULL(a) (NULL != a ? a : FLOM_NULL_STRING)
#endif
#ifndef STROREMPTY
/**
* STRing OR EMPTY:
* it can be used to print C strings even if they could be NULL; if passed
* string pointer is NULL, it returns ""
*/
# define STROREMPTY(a) (NULL != a ? a : "")
#endif
/**
* This value is the null file descriptor convention
*/
#define FLOM_NULL_FD -1
/**
* Format must be used in *printf family function to print a "uint32_t"
* value
*/
#if (SIZEOF_UINT32_T == SIZEOF_INT)
# define UINT32_T_FORMAT "%u"
#elif SIZEOF_UINT32_T == SIZEOF_LONG_INT
# define UINT32_T_FORMAT "%lu"
#elif SIZEOF_UINT32_T == SIZEOF_LONG_LONG_INT
# define UINT32_T_FORMAT "%llu"
#else
# error Unable to determine sizeof(uint32_t)
#endif
/**
* Format must be used in *printf family function to print a "uint64_t"
* value
*/
#if (SIZEOF_UINT64_T == SIZEOF_INT)
# define UINT64_T_FORMAT "%u"
#elif SIZEOF_UINT64_T == SIZEOF_LONG_INT
# define UINT64_T_FORMAT "%lu"
#elif SIZEOF_UINT64_T == SIZEOF_LONG_LONG_INT
# define UINT64_T_FORMAT "%llu"
#else
# error Unable to determine sizeof(uint64_t)
#endif
#ifdef HAVE_PID_T
# if SIZEOF_PID_T == SIZEOF_INT
# define PID_T_FORMAT "%d"
# elif SIZEOF_PID_T == SIZEOF_LONG_INT
# define PID_T_FORMAT "%l"
# else
# error Unable to determine sizeof(pid_t)
# endif
#else
# error pid_t type is not available
#endif
/**
* Format must be used in *printf family function to print a "size_t"
* value
*/
#if SIZEOF_SIZE_T == SIZEOF_INT
# define SIZE_T_FORMAT "%u"
#elif SIZEOF_SIZE_T == SIZEOF_LONG_INT
# define SIZE_T_FORMAT "%lu"
#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG_INT
# define SIZE_T_FORMAT "%llu"
#else
# error Unable to determine sizeof(size_t)
#endif
/**
* Format must be used in *printf family function to print a "ssize_t"
* value
*/
#if SIZEOF_SSIZE_T == SIZEOF_INT
# define SSIZE_T_FORMAT "%d"
#elif SSIZEOF_SIZE_T == SIZEOF_LONG_INT
# define SSIZE_T_FORMAT "%ld"
#elif SSIZEOF_SIZE_T == SIZEOF_LONG_LONG_INT
# define SSIZE_T_FORMAT "%lld"
#else
# error Unable to determine sizeof(ssize_t)
#endif
/**
* Format must be used in *printf family function to print a "socklen_t"
* value
*/
#if SIZEOF_SOCKLEN_T == SIZEOF_INT
# define SOCKLEN_T_FORMAT "%u"
#elif SIZEOF_SOCKLEN_T == SIZEOF_LONG_INT
# define SOCKLEN_T_FORMAT "%lu"
#elif SIZEOF_SOCKLEN_T == SIZEOF_LONG_LONG_INT
# define SOCKLEN_T_FORMAT "%llu"
#else
# error Unable to determine sizeof(socklen_t)
#endif
#ifdef HAVE_TIME_H
# if SIZEOF_CLOCK_T == SIZEOF_INT
# define CLOCK_T_FORMAT "%d"
# elif SIZEOF_CLOCK_T == SIZEOF_LONG_INT
# define CLOCK_T_FORMAT "%ld"
# elif SIZEOF_CLOCK_T == SIZEOF_LONG_LONG_INT
# define CLOCK_T_FORMAT "%lld"
# else
# error Unable to determine sizeof(clock_t)
# endif
#endif /* HAVE_TIME_H */
/**
* format for printing "off_t" values
*/
#if SIZEOF_OFF_T == SIZEOF_LONG_INT
# define OFF_T_FORMAT "%ld"
#elif SIZEOF_OFF_T == SIZEOF_LONG_LONG_INT
# define OFF_T_FORMAT "%lld"
#else
# error Unable to determine sizeof(off_t)
#endif
/**
* format for printing uintptr_t
*/
#if SIZEOF_UINTPTR_T == SIZEOF_INT
# define UINTPTR_T_FORMAT "%u"
#elif SIZEOF_UINTPTR_T == SIZEOF_LONG_INT
# define UINTPTR_T_FORMAT "%lu"
#elif SIZEOF_UINTPTR_T == SIZEOF_LONG_LONG_INT
# define UINTPTR_T_FORMAT "%llu"
#else
# error Unable to determine sizeof(uintptr_t)
#endif
#if SIZEOF_IN_PORT_T == SIZEOF_SHORT_INT
# define IN_PORT_T_FORMAT "%hu"
#else
# error Unable to determine format for in_port_t
#endif
/**
* Path separator
*/
#define FLOM_PATH_SEPARATOR '/'
/**
* Default buffer size for network operations
*/
#define FLOM_NETWORK_BUFFER_SIZE 1024
/**
* Default timeout for network operation (used as timeout parameter for
* "poll" function). This default value *** MUST *** be -1 (infinite timeout)
* because it's used by many blocking functions does not need timeout
* implementation
*/
#define FLOM_NETWORK_WAIT_TIMEOUT -1
#ifdef HAVE_STRCASESTR
/**
* If "strcasstr" is available, strings are checked case insensitive; else
* strings are checked case sensitive
*/
# define STRCASESTR(haystack,needle) strcasestr(haystack,needle)
#else
/**
* If "strcasstr" is available, strings are checked case insensitive; else
* strings are checked case sensitive
*/
# define STRCASESTR(haystack,needle) strstr(haystack,needle)
#endif
#ifndef HAVE_UINT8_T
# error "uint8_t is a necessary type"
#endif /* HAVE_UINT8_T */
#ifndef HAVE_UINT32_T
# error "uint32_t is a necessary type"
#endif /* HAVE_UINT32_T */
#ifndef HAVE_UINT64_T
# error "uint64_t is a necessary type"
#endif /* HAVE_UINT64_T */
/**
* A byte is the fundamental I/O unit
*/
typedef uint8_t byte_t;
#endif /* FLOM_DEFINES_H */