]> git.saurik.com Git - redis.git/blob - src/config.h
Redis 2.6.7
[redis.git] / src / config.h
1 /*
2 * Copyright (c) 2009-2012, Salvatore Sanfilippo <antirez at gmail dot com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Redis nor the names of its contributors may be used
14 * to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #ifndef __CONFIG_H
31 #define __CONFIG_H
32
33 #ifdef __APPLE__
34 #include <AvailabilityMacros.h>
35 #endif
36
37 /* Define redis_fstat to fstat or fstat64() */
38 #if defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_6)
39 #define redis_fstat fstat64
40 #define redis_stat stat64
41 #else
42 #define redis_fstat fstat
43 #define redis_stat stat
44 #endif
45
46 /* Test for proc filesystem */
47 #ifdef __linux__
48 #define HAVE_PROCFS 1
49 #endif
50
51 /* Test for task_info() */
52 #if defined(__APPLE__)
53 #define HAVE_TASKINFO 1
54 #endif
55
56 /* Test for backtrace() */
57 #if defined(__APPLE__) || defined(__linux__) || defined(__sun)
58 #define HAVE_BACKTRACE 1
59 #endif
60
61 /* Test for polling API */
62 #ifdef __linux__
63 #define HAVE_EPOLL 1
64 #endif
65
66 #if (defined(__APPLE__) && defined(MAC_OS_X_VERSION_10_6)) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined (__NetBSD__)
67 #define HAVE_KQUEUE 1
68 #endif
69
70 #ifdef __sun
71 #include <sys/feature_tests.h>
72 #ifdef _DTRACE_VERSION
73 #define HAVE_EVPORT 1
74 #endif
75 #endif
76
77 /* Define aof_fsync to fdatasync() in Linux and fsync() for all the rest */
78 #ifdef __linux__
79 #define aof_fsync fdatasync
80 #else
81 #define aof_fsync fsync
82 #endif
83
84 /* Define rdb_fsync_range to sync_file_range() on Linux, otherwise we use
85 * the plain fsync() call. */
86 #ifdef __linux__
87 #include <linux/version.h>
88 #include <features.h>
89 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
90 #if (LINUX_VERSION_CODE >= 0x020611 && __GLIBC_PREREQ(2, 6))
91 #define HAVE_SYNC_FILE_RANGE 1
92 #endif
93 #else
94 #if (LINUX_VERSION_CODE >= 0x020611)
95 #define HAVE_SYNC_FILE_RANGE 1
96 #endif
97 #endif
98 #endif
99
100 #ifdef HAVE_SYNC_FILE_RANGE
101 #define rdb_fsync_range(fd,off,size) sync_file_range(fd,off,size,SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE)
102 #else
103 #define rdb_fsync_range(fd,off,size) fsync(fd)
104 #endif
105
106 /* Byte ordering detection */
107 #include <sys/types.h> /* This will likely define BYTE_ORDER */
108
109 #ifndef BYTE_ORDER
110 #if (BSD >= 199103)
111 # include <machine/endian.h>
112 #else
113 #if defined(linux) || defined(__linux__)
114 # include <endian.h>
115 #else
116 #define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */
117 #define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
118 #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/
119
120 #if defined(__i386__) || defined(__x86_64__) || defined(__amd64__) || \
121 defined(vax) || defined(ns32000) || defined(sun386) || \
122 defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
123 defined(__alpha__) || defined(__alpha)
124 #define BYTE_ORDER LITTLE_ENDIAN
125 #endif
126
127 #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
128 defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
129 defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
130 defined(apollo) || defined(__convex__) || defined(_CRAY) || \
131 defined(__hppa) || defined(__hp9000) || \
132 defined(__hp9000s300) || defined(__hp9000s700) || \
133 defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc)
134 #define BYTE_ORDER BIG_ENDIAN
135 #endif
136 #endif /* linux */
137 #endif /* BSD */
138 #endif /* BYTE_ORDER */
139
140 #if defined(__BYTE_ORDER) && !defined(BYTE_ORDER)
141 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
142 #define BYTE_ORDER LITTLE_ENDIAN
143 #else
144 #define BYTE_ORDER BIG_ENDIAN
145 #endif
146 #endif
147
148 #if !defined(BYTE_ORDER) || \
149 (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN)
150 /* you must determine what the correct bit order is for
151 * your compiler - the next line is an intentional error
152 * which will force your compiles to bomb until you fix
153 * the above macros.
154 */
155 #error "Undefined or invalid BYTE_ORDER"
156 #endif
157
158 #if (__i386 || __amd64) && __GNUC__
159 #define GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
160 #if GNUC_VERSION >= 40100
161 #define HAVE_ATOMIC
162 #endif
163 #endif
164
165
166 #endif