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 *************************************************************************************************/
17 #ifndef _MYCONF_H // duplication check
22 /*************************************************************************************************
23 * system discrimination
24 *************************************************************************************************/
27 #if defined(__linux__)
30 #define ESTSYSNAME "Linux"
32 #elif defined(__FreeBSD__)
35 #define ESTSYSNAME "FreeBSD"
37 #elif defined(__NetBSD__)
40 #define ESTSYSNAME "NetBSD"
42 #elif defined(__OpenBSD__)
45 #define ESTSYSNAME "OpenBSD"
47 #elif defined(__sun__)
50 #define ESTSYSNAME "SunOS"
55 #define ESTSYSNAME "HP-UX"
60 #define ESTSYSNAME "Tru64"
65 #define ESTSYSNAME "AIX"
67 #elif defined(__APPLE__) && defined(__MACH__)
70 #define ESTSYSNAME "Mac OS X"
72 #elif defined(_MSC_VER)
75 #define ESTSYSNAME "Windows (VC++)"
80 #define ESTSYSNAME "Windows (MinGW)"
82 #elif defined(__CYGWIN__)
85 #define ESTSYSNAME "Windows (Cygwin)"
90 #define ESTSYSNAME "Generic"
96 /*************************************************************************************************
98 *************************************************************************************************/
102 #define TCDODEBUG(TC_expr) \
106 #define TCDODEBUG(TC_expr) \
112 #define TCSWAB16(TC_num) \
114 ((TC_num & 0x00ffU) << 8) | \
115 ((TC_num & 0xff00U) >> 8) \
118 #define TCSWAB32(TC_num) \
120 ((TC_num & 0x000000ffUL) << 24) | \
121 ((TC_num & 0x0000ff00UL) << 8) | \
122 ((TC_num & 0x00ff0000UL) >> 8) | \
123 ((TC_num & 0xff000000UL) >> 24) \
126 #define TCSWAB64(TC_num) \
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) \
138 #if defined(_MYBIGEND) || defined(_MYSWAB)
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)
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)
156 #if defined(_MYNOZLIB)
162 #if defined(_MYNOPTHREAD)
163 #define TCUSEPTHREAD 0
165 #define TCUSEPTHREAD 1
168 #if defined(_MYMICROYIELD)
169 #define TCMICROYIELD 1
171 #define TCMICROYIELD 0
174 #define sizeof(a) ((int)sizeof(a))
176 int _tc_dummyfunc(void);
177 int _tc_dummyfuncv(int a, ...);
181 /*************************************************************************************************
183 *************************************************************************************************/
202 #include <inttypes.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>
223 /*************************************************************************************************
224 * notation of filesystems
225 *************************************************************************************************/
228 #define MYPATHCHR '/'
229 #define MYPATHSTR "/"
232 #define MYCDIRSTR "."
233 #define MYPDIRSTR ".."
237 /*************************************************************************************************
239 *************************************************************************************************/
249 extern char *(*_tc_deflate)(const char *, int, int *, int);
251 extern char *(*_tc_inflate)(const char *, int, int *, int);
253 extern unsigned int (*_tc_getcrc)(const char *, int);
257 /*************************************************************************************************
258 * for POSIX thread disability
259 *************************************************************************************************/
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))
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))
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))
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))
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))
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) \
302 #define pthread_detach(TC_th) 0
306 #if TCUSEPTHREAD && TCMICROYIELD
307 #define TCTESTYIELD() \
309 static uint32_t cnt = 0; \
310 if(((++cnt) & (0x20 - 1)) == 0){ \
312 if(cnt > 0x1000) cnt = (uint32_t)time(NULL) % 0x1000; \
316 #define assert(TC_expr) \
319 fprintf(stderr, "assertion failed: %s\n", #TC_expr); \
325 #define TCTESTYIELD() \
332 /*************************************************************************************************
333 * utilities for implementation
334 *************************************************************************************************/
337 #define TCNUMBUFSIZ 32 // size of a buffer for a number
339 /* set a buffer for a variable length number */
340 #define TCSETVNUMBUF(TC_len, TC_buf, TC_num) \
342 int _TC_num = (TC_num); \
344 ((signed char *)(TC_buf))[0] = 0; \
348 while(_TC_num > 0){ \
349 int _TC_rem = _TC_num & 0x7f; \
352 ((signed char *)(TC_buf))[(TC_len)] = -_TC_rem - 1; \
354 ((signed char *)(TC_buf))[(TC_len)] = _TC_rem; \
361 /* set a buffer for a variable length number of 64-bit */
362 #define TCSETVNUMBUF64(TC_len, TC_buf, TC_num) \
364 long long int _TC_num = (TC_num); \
366 ((signed char *)(TC_buf))[0] = 0; \
370 while(_TC_num > 0){ \
371 int _TC_rem = _TC_num & 0x7f; \
374 ((signed char *)(TC_buf))[(TC_len)] = -_TC_rem - 1; \
376 ((signed char *)(TC_buf))[(TC_len)] = _TC_rem; \
383 /* read a variable length buffer */
384 #define TCREADVNUMBUF(TC_buf, TC_num, TC_step) \
390 if(((signed char *)(TC_buf))[_TC_i] >= 0){ \
391 TC_num += ((signed char *)(TC_buf))[_TC_i] * _TC_base; \
394 TC_num += _TC_base * (((signed char *)(TC_buf))[_TC_i] + 1) * -1; \
398 (TC_step) = _TC_i + 1; \
401 /* read a variable length buffer */
402 #define TCREADVNUMBUF64(TC_buf, TC_num, TC_step) \
405 long long int _TC_base = 1; \
408 if(((signed char *)(TC_buf))[_TC_i] >= 0){ \
409 TC_num += ((signed char *)(TC_buf))[_TC_i] * _TC_base; \
412 TC_num += _TC_base * (((signed char *)(TC_buf))[_TC_i] + 1) * -1; \
416 (TC_step) = _TC_i + 1; \
419 /* Compare keys of two records by lexical order. */
420 #define TCCMPLEXICAL(TC_rv, TC_aptr, TC_asiz, TC_bptr, TC_bsiz) \
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]; \
430 if((TC_rv) == 0) (TC_rv) = (TC_asiz) - (TC_bsiz); \
435 #endif // duplication check