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_PROC_STAT 1 49 #define HAVE_PROC_MAPS 1 50 #define HAVE_PROC_SMAPS 1 51 #define HAVE_PROC_SOMAXCONN 1 52 #endif 53 54 /* Test for task_info() */ 55 #if defined(__APPLE__) 56 #define HAVE_TASKINFO 1 57 #endif 58 59 /* Test for backtrace() */ 60 #if defined(__APPLE__) || defined(__linux__) 61 #define HAVE_BACKTRACE 1 62 #endif 63 64 /* MSG_NOSIGNAL. */ 65 #ifdef __linux__ 66 #define HAVE_MSG_NOSIGNAL 1 67 #endif 68 69 /* Test for polling API */ 70 #ifdef __linux__ 71 #define HAVE_EPOLL 1 72 #endif 73 74 #if (defined(__APPLE__) && defined(MAC_OS_X_VERSION_10_6)) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined (__NetBSD__) 75 #define HAVE_KQUEUE 1 76 #endif 77 78 #ifdef __sun 79 #include <sys/feature_tests.h> 80 #ifdef _DTRACE_VERSION 81 #define HAVE_EVPORT 1 82 #endif 83 #endif 84 85 /* Define aof_fsync to fdatasync() in Linux and fsync() for all the rest */ 86 #ifdef __linux__ 87 #define aof_fsync fdatasync 88 #else 89 #define aof_fsync fsync 90 #endif 91 92 /* Define rdb_fsync_range to sync_file_range() on Linux, otherwise we use 93 * the plain fsync() call. */ 94 #ifdef __linux__ 95 #include <linux/version.h> 96 #include <features.h> 97 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ) 98 #if (LINUX_VERSION_CODE >= 0x020611 && __GLIBC_PREREQ(2, 6)) 99 #define HAVE_SYNC_FILE_RANGE 1 100 #endif 101 #else 102 #if (LINUX_VERSION_CODE >= 0x020611) 103 #define HAVE_SYNC_FILE_RANGE 1 104 #endif 105 #endif 106 #endif 107 108 #ifdef HAVE_SYNC_FILE_RANGE 109 #define rdb_fsync_range(fd,off,size) sync_file_range(fd,off,size,SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE) 110 #else 111 #define rdb_fsync_range(fd,off,size) fsync(fd) 112 #endif 113 114 /* Check if we can use setproctitle(). 115 * BSD systems have support for it, we provide an implementation for 116 * Linux and osx. */ 117 #if (defined __NetBSD__ || defined __FreeBSD__ || defined __OpenBSD__) 118 #define USE_SETPROCTITLE 119 #endif 120 121 #if (defined __linux || defined __APPLE__) 122 #define USE_SETPROCTITLE 123 #define INIT_SETPROCTITLE_REPLACEMENT 124 void spt_init(int argc, char *argv[]); 125 void setproctitle(const char *fmt, ...); 126 #endif 127 128 /* Byte ordering detection */ 129 #include <sys/types.h> /* This will likely define BYTE_ORDER */ 130 131 #ifndef BYTE_ORDER 132 #if (BSD >= 199103) 133 # include <machine/endian.h> 134 #else 135 #if defined(linux) || defined(__linux__) 136 # include <endian.h> 137 #else 138 #define LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */ 139 #define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */ 140 #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp)*/ 141 142 #if defined(__i386__) || defined(__x86_64__) || defined(__amd64__) || \ 143 defined(vax) || defined(ns32000) || defined(sun386) || \ 144 defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \ 145 defined(__alpha__) || defined(__alpha) 146 #define BYTE_ORDER LITTLE_ENDIAN 147 #endif 148 149 #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \ 150 defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \ 151 defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\ 152 defined(apollo) || defined(__convex__) || defined(_CRAY) || \ 153 defined(__hppa) || defined(__hp9000) || \ 154 defined(__hp9000s300) || defined(__hp9000s700) || \ 155 defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc) 156 #define BYTE_ORDER BIG_ENDIAN 157 #endif 158 #endif /* linux */ 159 #endif /* BSD */ 160 #endif /* BYTE_ORDER */ 161 162 /* Sometimes after including an OS-specific header that defines the 163 * endianess we end with __BYTE_ORDER but not with BYTE_ORDER that is what 164 * the Redis code uses. In this case let's define everything without the 165 * underscores. */ 166 #ifndef BYTE_ORDER 167 #ifdef __BYTE_ORDER 168 #if defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN) 169 #ifndef LITTLE_ENDIAN 170 #define LITTLE_ENDIAN __LITTLE_ENDIAN 171 #endif 172 #ifndef BIG_ENDIAN 173 #define BIG_ENDIAN __BIG_ENDIAN 174 #endif 175 #if (__BYTE_ORDER == __LITTLE_ENDIAN) 176 #define BYTE_ORDER LITTLE_ENDIAN 177 #else 178 #define BYTE_ORDER BIG_ENDIAN 179 #endif 180 #endif 181 #endif 182 #endif 183 184 #if !defined(BYTE_ORDER) || \ 185 (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN) 186 /* you must determine what the correct bit order is for 187 * your compiler - the next line is an intentional error 188 * which will force your compiles to bomb until you fix 189 * the above macros. 190 */ 191 #error "Undefined or invalid BYTE_ORDER" 192 #endif 193 194 #if (__i386 || __amd64 || __powerpc__) && __GNUC__ 195 #define GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 196 #if defined(__clang__) 197 #define HAVE_ATOMIC 198 #endif 199 #if (defined(__GLIBC__) && defined(__GLIBC_PREREQ)) 200 #if (GNUC_VERSION >= 40100 && __GLIBC_PREREQ(2, 6)) 201 #define HAVE_ATOMIC 202 #endif 203 #endif 204 #endif 205 206 #endif 207