]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/tokyocabinet/myconf.h
ebl Add tokyocabinet source to bacula
[bacula/bacula] / bacula / src / lib / tokyocabinet / myconf.h
1 /*************************************************************************************************
2  * System-dependent configurations of Tokyo Cabinet
3  *                                                      Copyright (C) 2006-2008 Mikio Hirabayashi
4  * This file is part of Tokyo Cabinet.
5  * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
6  * the GNU Lesser General Public License as published by the Free Software Foundation; either
7  * version 2.1 of the License or any later version.  Tokyo Cabinet is distributed in the hope
8  * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
10  * License for more details.
11  * You should have received a copy of the GNU Lesser General Public License along with Tokyo
12  * Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
13  * Boston, MA 02111-1307 USA.
14  *************************************************************************************************/
15
16
17 #ifndef _MYCONF_H                        // duplication check
18 #define _MYCONF_H
19
20
21
22 /*************************************************************************************************
23  * system discrimination
24  *************************************************************************************************/
25
26
27 #if defined(__linux__)
28
29 #define _SYS_LINUX_
30 #define ESTSYSNAME  "Linux"
31
32 #elif defined(__FreeBSD__)
33
34 #define _SYS_FREEBSD_
35 #define ESTSYSNAME  "FreeBSD"
36
37 #elif defined(__NetBSD__)
38
39 #define _SYS_NETBSD_
40 #define ESTSYSNAME  "NetBSD"
41
42 #elif defined(__OpenBSD__)
43
44 #define _SYS_OPENBSD_
45 #define ESTSYSNAME  "OpenBSD"
46
47 #elif defined(__sun__)
48
49 #define _SYS_SUNOS_
50 #define ESTSYSNAME  "SunOS"
51
52 #elif defined(__hpux)
53
54 #define _SYS_HPUX_
55 #define ESTSYSNAME  "HP-UX"
56
57 #elif defined(__osf)
58
59 #define _SYS_TRU64_
60 #define ESTSYSNAME  "Tru64"
61
62 #elif defined(_AIX)
63
64 #define _SYS_AIX_
65 #define ESTSYSNAME  "AIX"
66
67 #elif defined(__APPLE__) && defined(__MACH__)
68
69 #define _SYS_MACOSX_
70 #define ESTSYSNAME  "Mac OS X"
71
72 #elif defined(_MSC_VER)
73
74 #define _SYS_MSVC_
75 #define ESTSYSNAME  "Windows (VC++)"
76
77 #elif defined(_WIN32)
78
79 #define _SYS_MINGW_
80 #define ESTSYSNAME  "Windows (MinGW)"
81
82 #elif defined(__CYGWIN__)
83
84 #define _SYS_CYGWIN_
85 #define ESTSYSNAME  "Windows (Cygwin)"
86
87 #else
88
89 #define _SYS_GENERIC_
90 #define ESTSYSNAME  "Generic"
91
92 #endif
93
94
95
96 /*************************************************************************************************
97  * common settings
98  *************************************************************************************************/
99
100
101 #if defined(NDEBUG)
102 #define TCDODEBUG(TC_expr) \
103   do { \
104   } while(false)
105 #else
106 #define TCDODEBUG(TC_expr) \
107   do { \
108     TC_expr; \
109   } while(false)
110 #endif
111
112 #define TCSWAB16(TC_num) \
113   ( \
114    ((TC_num & 0x00ffU) << 8) | \
115    ((TC_num & 0xff00U) >> 8) \
116   )
117
118 #define TCSWAB32(TC_num) \
119   ( \
120    ((TC_num & 0x000000ffUL) << 24) | \
121    ((TC_num & 0x0000ff00UL) << 8) | \
122    ((TC_num & 0x00ff0000UL) >> 8) | \
123    ((TC_num & 0xff000000UL) >> 24) \
124   )
125
126 #define TCSWAB64(TC_num) \
127   ( \
128    ((TC_num & 0x00000000000000ffULL) << 56) | \
129    ((TC_num & 0x000000000000ff00ULL) << 40) | \
130    ((TC_num & 0x0000000000ff0000ULL) << 24) | \
131    ((TC_num & 0x00000000ff000000ULL) << 8) | \
132    ((TC_num & 0x000000ff00000000ULL) >> 8) | \
133    ((TC_num & 0x0000ff0000000000ULL) >> 24) | \
134    ((TC_num & 0x00ff000000000000ULL) >> 40) | \
135    ((TC_num & 0xff00000000000000ULL) >> 56) \
136   )
137
138 #if defined(_MYBIGEND) || defined(_MYSWAB)
139 #define TCBIGEND       1
140 #define TCHTOIS(TC_num)   TCSWAB16(TC_num)
141 #define TCHTOIL(TC_num)   TCSWAB32(TC_num)
142 #define TCHTOILL(TC_num)  TCSWAB64(TC_num)
143 #define TCITOHS(TC_num)   TCSWAB16(TC_num)
144 #define TCITOHL(TC_num)   TCSWAB32(TC_num)
145 #define TCITOHLL(TC_num)  TCSWAB64(TC_num)
146 #else
147 #define TCBIGEND       0
148 #define TCHTOIS(TC_num)   (TC_num)
149 #define TCHTOIL(TC_num)   (TC_num)
150 #define TCHTOILL(TC_num)  (TC_num)
151 #define TCITOHS(TC_num)   (TC_num)
152 #define TCITOHL(TC_num)   (TC_num)
153 #define TCITOHLL(TC_num)  (TC_num)
154 #endif
155
156 #if defined(_MYNOZLIB)
157 #define TCUSEZLIB      0
158 #else
159 #define TCUSEZLIB      1
160 #endif
161
162 #if defined(_MYNOPTHREAD)
163 #define TCUSEPTHREAD   0
164 #else
165 #define TCUSEPTHREAD   1
166 #endif
167
168 #if defined(_MYMICROYIELD)
169 #define TCMICROYIELD   1
170 #else
171 #define TCMICROYIELD   0
172 #endif
173
174 #define sizeof(a)      ((int)sizeof(a))
175
176 int _tc_dummyfunc(void);
177 int _tc_dummyfuncv(int a, ...);
178
179
180
181 /*************************************************************************************************
182  * general headers
183  *************************************************************************************************/
184
185
186 #include <assert.h>
187 #include <ctype.h>
188 #include <errno.h>
189 #include <float.h>
190 #include <limits.h>
191 #include <locale.h>
192 #include <math.h>
193 #include <setjmp.h>
194 #include <stdarg.h>
195 #include <stddef.h>
196 #include <stdio.h>
197 #include <stdlib.h>
198 #include <signal.h>
199 #include <string.h>
200 #include <time.h>
201
202 #include <inttypes.h>
203 #include <stdbool.h>
204 #include <stdint.h>
205
206 #include <unistd.h>
207 #include <sys/types.h>
208 #include <sys/stat.h>
209 #include <sys/mman.h>
210 #include <sys/time.h>
211 #include <sys/times.h>
212 #include <fcntl.h>
213 #include <dirent.h>
214 #include <regex.h>
215 #include <glob.h>
216
217 #if TCUSEPTHREAD
218 #include <pthread.h>
219 #endif
220
221
222
223 /*************************************************************************************************
224  * notation of filesystems
225  *************************************************************************************************/
226
227
228 #define MYPATHCHR       '/'
229 #define MYPATHSTR       "/"
230 #define MYEXTCHR        '.'
231 #define MYEXTSTR        "."
232 #define MYCDIRSTR       "."
233 #define MYPDIRSTR       ".."
234
235
236
237 /*************************************************************************************************
238  * for ZLIB
239  *************************************************************************************************/
240
241
242 enum {
243   _TCZMZLIB,
244   _TCZMRAW,
245   _TCZMGZIP
246 };
247
248
249 extern char *(*_tc_deflate)(const char *, int, int *, int);
250
251 extern char *(*_tc_inflate)(const char *, int, int *, int);
252
253 extern unsigned int (*_tc_getcrc)(const char *, int);
254
255
256
257 /*************************************************************************************************
258  * for POSIX thread disability
259  *************************************************************************************************/
260
261
262 #if ! TCUSEPTHREAD
263
264 #define pthread_once_t                   int
265 #undef PTHREAD_ONCE_INIT
266 #define PTHREAD_ONCE_INIT                0
267 #define pthread_once(TC_a, TC_b)         _tc_dummyfuncv((int)(TC_a), (TC_b))
268
269 #define pthread_mutexattr_t              int
270 #undef PTHREAD_MUTEX_RECURSIVE
271 #define PTHREAD_MUTEX_RECURSIVE          0
272 #define pthread_mutexattr_init(TC_a)     _tc_dummyfuncv((int)(TC_a))
273 #define pthread_mutexattr_destroy(TC_a)  _tc_dummyfuncv((int)(TC_a))
274 #define pthread_mutexattr_settype(TC_a, TC_b)  _tc_dummyfuncv((int)(TC_a), (TC_b))
275
276 #define pthread_mutex_t                  int
277 #undef PTHREAD_MUTEX_INITIALIZER
278 #define PTHREAD_MUTEX_INITIALIZER        0
279 #define pthread_mutex_init(TC_a, TC_b)   _tc_dummyfuncv((int)(TC_a), (TC_b))
280 #define pthread_mutex_destroy(TC_a)      _tc_dummyfuncv((int)(TC_a))
281 #define pthread_mutex_lock(TC_a)         _tc_dummyfuncv((int)(TC_a))
282 #define pthread_mutex_unlock(TC_a)       _tc_dummyfuncv((int)(TC_a))
283
284 #define pthread_rwlock_t                 int
285 #undef PTHREAD_RWLOCK_INITIALIZER
286 #define PTHREAD_RWLOCK_INITIALIZER       0
287 #define pthread_rwlock_init(TC_a, TC_b)  _tc_dummyfuncv((int)(TC_a), (TC_b))
288 #define pthread_rwlock_destroy(TC_a)     _tc_dummyfuncv((int)(TC_a))
289 #define pthread_rwlock_rdlock(TC_a)      _tc_dummyfuncv((int)(TC_a))
290 #define pthread_rwlock_wrlock(TC_a)      _tc_dummyfuncv((int)(TC_a))
291 #define pthread_rwlock_unlock(TC_a)      _tc_dummyfuncv((int)(TC_a))
292
293 #define pthread_key_create(TC_a, TC_b)   _tc_dummyfuncv((int)(TC_a), (TC_b))
294 #define pthread_key_delete(TC_a)         _tc_dummyfuncv((int)(TC_a))
295 #define pthread_setspecific(TC_a, TC_b)  _tc_dummyfuncv((int)(TC_a))
296 #define pthread_getspecific(TC_a)        _tc_dummyfuncv((int)(TC_a))
297
298 #define pthread_create(TC_th, TC_attr, TC_func, TC_arg) \
299   (*(TC_th) = 0, (TC_func)(TC_arg), 0)
300 #define pthread_join(TC_th, TC_rv) \
301   (*(TC_rv) = NULL, 0)
302 #define pthread_detach(TC_th)         0
303
304 #endif
305
306 #if TCUSEPTHREAD && TCMICROYIELD
307 #define TCTESTYIELD() \
308   do { \
309     static uint32_t cnt = 0; \
310     if(((++cnt) & (0x20 - 1)) == 0){ \
311       pthread_yield(); \
312       if(cnt > 0x1000) cnt = (uint32_t)time(NULL) % 0x1000; \
313     } \
314   } while(false)
315 #undef assert
316 #define assert(TC_expr) \
317   do { \
318     if(!(TC_expr)){ \
319       fprintf(stderr, "assertion failed: %s\n", #TC_expr); \
320       abort(); \
321     } \
322     TCTESTYIELD(); \
323   } while(false)
324 #else
325 #define TCTESTYIELD() \
326   do { \
327   } while(false);
328 #endif
329
330
331
332 /*************************************************************************************************
333  * utilities for implementation
334  *************************************************************************************************/
335
336
337 #define TCNUMBUFSIZ    32                // size of a buffer for a number
338
339 /* set a buffer for a variable length number */
340 #define TCSETVNUMBUF(TC_len, TC_buf, TC_num) \
341   do { \
342     int _TC_num = (TC_num); \
343     if(_TC_num == 0){ \
344       ((signed char *)(TC_buf))[0] = 0; \
345       (TC_len) = 1; \
346     } else { \
347       (TC_len) = 0; \
348       while(_TC_num > 0){ \
349         int _TC_rem = _TC_num & 0x7f; \
350         _TC_num >>= 7; \
351         if(_TC_num > 0){ \
352           ((signed char *)(TC_buf))[(TC_len)] = -_TC_rem - 1; \
353         } else { \
354           ((signed char *)(TC_buf))[(TC_len)] = _TC_rem; \
355         } \
356         (TC_len)++; \
357       } \
358     } \
359   } while(false)
360
361 /* set a buffer for a variable length number of 64-bit */
362 #define TCSETVNUMBUF64(TC_len, TC_buf, TC_num) \
363   do { \
364     long long int _TC_num = (TC_num); \
365     if(_TC_num == 0){ \
366       ((signed char *)(TC_buf))[0] = 0; \
367       (TC_len) = 1; \
368     } else { \
369       (TC_len) = 0; \
370       while(_TC_num > 0){ \
371         int _TC_rem = _TC_num & 0x7f; \
372         _TC_num >>= 7; \
373         if(_TC_num > 0){ \
374           ((signed char *)(TC_buf))[(TC_len)] = -_TC_rem - 1; \
375         } else { \
376           ((signed char *)(TC_buf))[(TC_len)] = _TC_rem; \
377         } \
378         (TC_len)++; \
379       } \
380     } \
381   } while(false)
382
383 /* read a variable length buffer */
384 #define TCREADVNUMBUF(TC_buf, TC_num, TC_step) \
385   do { \
386     TC_num = 0; \
387     int _TC_base = 1; \
388     int _TC_i = 0; \
389     while(true){ \
390       if(((signed char *)(TC_buf))[_TC_i] >= 0){ \
391         TC_num += ((signed char *)(TC_buf))[_TC_i] * _TC_base; \
392         break; \
393       } \
394       TC_num += _TC_base * (((signed char *)(TC_buf))[_TC_i] + 1) * -1; \
395       _TC_base <<= 7; \
396       _TC_i++; \
397     } \
398     (TC_step) = _TC_i + 1; \
399   } while(false)
400
401 /* read a variable length buffer */
402 #define TCREADVNUMBUF64(TC_buf, TC_num, TC_step) \
403   do { \
404     TC_num = 0; \
405     long long int _TC_base = 1; \
406     int _TC_i = 0; \
407     while(true){ \
408       if(((signed char *)(TC_buf))[_TC_i] >= 0){ \
409         TC_num += ((signed char *)(TC_buf))[_TC_i] * _TC_base; \
410         break; \
411       } \
412       TC_num += _TC_base * (((signed char *)(TC_buf))[_TC_i] + 1) * -1; \
413       _TC_base <<= 7; \
414       _TC_i++; \
415     } \
416     (TC_step) = _TC_i + 1; \
417   } while(false)
418
419 /* Compare keys of two records by lexical order. */
420 #define TCCMPLEXICAL(TC_rv, TC_aptr, TC_asiz, TC_bptr, TC_bsiz) \
421   do { \
422     (TC_rv) = 0; \
423     int _TC_min = (TC_asiz) < (TC_bsiz) ? (TC_asiz) : (TC_bsiz); \
424     for(int _TC_i = 0; _TC_i < _TC_min; _TC_i++){ \
425       if(((unsigned char *)(TC_aptr))[_TC_i] != ((unsigned char *)(TC_bptr))[_TC_i]){ \
426         (TC_rv) = ((unsigned char *)(TC_aptr))[_TC_i] - ((unsigned char *)(TC_bptr))[_TC_i]; \
427         break; \
428       } \
429     } \
430     if((TC_rv) == 0) (TC_rv) = (TC_asiz) - (TC_bsiz); \
431   } while(false)
432
433
434
435 #endif                                   // duplication check
436
437
438 // END OF FILE