Back to home page

Redis cross reference

 
 

    


0001 /*
0002  * Copyright (c) 2009-2012, Salvatore Sanfilippo <antirez at gmail dot com>
0003  * All rights reserved.
0004  *
0005  * Redistribution and use in source and binary forms, with or without
0006  * modification, are permitted provided that the following conditions are met:
0007  *
0008  *   * Redistributions of source code must retain the above copyright notice,
0009  *     this list of conditions and the following disclaimer.
0010  *   * Redistributions in binary form must reproduce the above copyright
0011  *     notice, this list of conditions and the following disclaimer in the
0012  *     documentation and/or other materials provided with the distribution.
0013  *   * Neither the name of Redis nor the names of its contributors may be used
0014  *     to endorse or promote products derived from this software without
0015  *     specific prior written permission.
0016  *
0017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0027  * POSSIBILITY OF SUCH DAMAGE.
0028  */
0029 
0030 #ifndef __CONFIG_H
0031 #define __CONFIG_H
0032 
0033 #ifdef __APPLE__
0034 #include <AvailabilityMacros.h>
0035 #endif
0036 
0037 /* Define redis_fstat to fstat or fstat64() */
0038 #if defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_6)
0039 #define redis_fstat fstat64
0040 #define redis_stat stat64
0041 #else
0042 #define redis_fstat fstat
0043 #define redis_stat stat
0044 #endif
0045 
0046 /* Test for proc filesystem */
0047 #ifdef __linux__
0048 #define HAVE_PROCFS 1
0049 #endif
0050 
0051 /* Test for task_info() */
0052 #if defined(__APPLE__)
0053 #define HAVE_TASKINFO 1
0054 #endif
0055 
0056 /* Test for backtrace() */
0057 #if defined(__APPLE__) || defined(__linux__)
0058 #define HAVE_BACKTRACE 1
0059 #endif
0060 
0061 /* Test for polling API */
0062 #ifdef __linux__
0063 #define HAVE_EPOLL 1
0064 #endif
0065 
0066 #if (defined(__APPLE__) && defined(MAC_OS_X_VERSION_10_6)) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined (__NetBSD__)
0067 #define HAVE_KQUEUE 1
0068 #endif
0069 
0070 #ifdef __sun
0071 #include <sys/feature_tests.h>
0072 #ifdef _DTRACE_VERSION
0073 #define HAVE_EVPORT 1
0074 #endif
0075 #endif
0076 
0077 /* Define aof_fsync to fdatasync() in Linux and fsync() for all the rest */
0078 #ifdef __linux__
0079 #define aof_fsync fdatasync
0080 #else
0081 #define aof_fsync fsync
0082 #endif
0083 
0084 /* Define rdb_fsync_range to sync_file_range() on Linux, otherwise we use
0085  * the plain fsync() call. */
0086 #ifdef __linux__
0087 #include <linux/version.h>
0088 #include <features.h>
0089 #if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
0090 #if (LINUX_VERSION_CODE >= 0x020611 && __GLIBC_PREREQ(2, 6))
0091 #define HAVE_SYNC_FILE_RANGE 1
0092 #endif
0093 #else
0094 #if (LINUX_VERSION_CODE >= 0x020611)
0095 #define HAVE_SYNC_FILE_RANGE 1
0096 #endif
0097 #endif
0098 #endif
0099 
0100 #ifdef HAVE_SYNC_FILE_RANGE
0101 #define rdb_fsync_range(fd,off,size) sync_file_range(fd,off,size,SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE)
0102 #else
0103 #define rdb_fsync_range(fd,off,size) fsync(fd)
0104 #endif
0105 
0106 /* Byte ordering detection */
0107 #include <sys/types.h>
0108 
0109 #ifndef BYTE_ORDER
0110 #if (BSD >= 199103)
0111 # include <machine/endian.h>
0112 #else
0113 #if defined(linux) || defined(__linux__)
0114 # include <endian.h>
0115 #else
0116 #define LITTLE_ENDIAN   1234    /* least-significant byte first (vax, pc) */
0117 #define BIG_ENDIAN  4321    /* most-significant byte first (IBM, net) */
0118 #define PDP_ENDIAN  3412    /* LSB first in word, MSW first in long (pdp)*/
0119 
0120 #if defined(__i386__) || defined(__x86_64__) || defined(__amd64__) || \
0121    defined(vax) || defined(ns32000) || defined(sun386) || \
0122    defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
0123    defined(__alpha__) || defined(__alpha)
0124 #define BYTE_ORDER    LITTLE_ENDIAN
0125 #endif
0126 
0127 #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
0128     defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
0129     defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\
0130     defined(apollo) || defined(__convex__) || defined(_CRAY) || \
0131     defined(__hppa) || defined(__hp9000) || \
0132     defined(__hp9000s300) || defined(__hp9000s700) || \
0133     defined (BIT_ZERO_ON_LEFT) || defined(m68k) || defined(__sparc)
0134 #define BYTE_ORDER  BIG_ENDIAN
0135 #endif
0136 #endif /* linux */
0137 #endif /* BSD */
0138 #endif /* BYTE_ORDER */
0139 
0140 /* Sometimes after including an OS-specific header that defines the
0141  * endianess we end with __BYTE_ORDER but not with BYTE_ORDER that is what
0142  * the Redis code uses. In this case let's define everything without the
0143  * underscores. */
0144 #ifndef BYTE_ORDER
0145 #ifdef __BYTE_ORDER
0146 #if defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
0147 #ifndef LITTLE_ENDIAN
0148 #define LITTLE_ENDIAN __LITTLE_ENDIAN
0149 #endif
0150 #ifndef BIG_ENDIAN
0151 #define BIG_ENDIAN __BIG_ENDIAN
0152 #endif
0153 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
0154 #define BYTE_ORDER LITTLE_ENDIAN
0155 #else
0156 #define BYTE_ORDER BIG_ENDIAN
0157 #endif
0158 #endif
0159 #endif
0160 #endif
0161 
0162 #if !defined(BYTE_ORDER) || \
0163     (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN)
0164     /* you must determine what the correct bit order is for
0165      * your compiler - the next line is an intentional error
0166      * which will force your compiles to bomb until you fix
0167      * the above macros.
0168      */
0169 #error "Undefined or invalid BYTE_ORDER"
0170 #endif
0171 
0172 #if (__i386 || __amd64) && __GNUC__
0173 #define GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
0174 #if GNUC_VERSION >= 40100
0175 #define HAVE_ATOMIC
0176 #endif
0177 #endif
0178 
0179 #endif