|
xrootd
|
00001 #ifndef __XRDSYS_PLATFORM_H__ 00002 #define __XRDSYS_PLATFORM_H__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S y s P l a t f o r m . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC03-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id: XrdSysPlatform.hh 37681 2010-12-21 16:40:47Z rdm $ 00014 00015 // Include stdlib so that ENDIAN macros are defined properly 00016 // 00017 #include <stdlib.h> 00018 #ifdef __linux__ 00019 #include <memory.h> 00020 #include <string.h> 00021 #include <sys/types.h> 00022 #include <asm/param.h> 00023 #include <byteswap.h> 00024 #define MAXNAMELEN NAME_MAX 00025 #endif 00026 #ifdef __macos__ 00027 #include <AvailabilityMacros.h> 00028 #include <sys/types.h> 00029 #define fdatasync(x) fsync(x) 00030 #define MAXNAMELEN NAME_MAX 00031 #ifndef dirent64 00032 # define dirent64 dirent 00033 #endif 00034 #ifndef off64_t 00035 #define off64_t int64_t 00036 #endif 00037 #if (!defined(MAC_OS_X_VERSION_10_5) || \ 00038 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5) 00039 #ifndef stat64 00040 # define stat64 stat 00041 #endif 00042 #endif 00043 #endif 00044 #ifdef __FreeBSD__ 00045 #include <sys/types.h> 00046 #endif 00047 00048 #ifdef __solaris__ 00049 #define posix_memalign(memp, algn, sz) \ 00050 ((*memp = memalign(algn, sz)) ? 0 : ENOMEM) 00051 #endif 00052 00053 #if defined(__linux__) || defined(__macos__) || defined(__FreeBSD__) 00054 00055 #define S_IAMB 0x1FF /* access mode bits */ 00056 00057 #define F_DUP2FD F_DUPFD 00058 00059 #define STATFS statfs 00060 #define STATFS_BUFF struct statfs 00061 00062 #define FS_BLKFACT 4 00063 00064 #define FLOCK_t struct flock 00065 00066 typedef off_t offset_t; 00067 00068 #define GTZ_NULL (struct timezone *)0 00069 00070 #else 00071 00072 #define STATFS statvfs 00073 #define STATFS_BUFF struct statvfs 00074 00075 #define FS_BLKFACT 1 00076 00077 #define SHMDT_t char * 00078 00079 #define FLOCK_t flock_t 00080 00081 #define GTZ_NULL (void *)0 00082 00083 #endif 00084 00085 #ifdef __linux__ 00086 00087 #define SHMDT_t const void * 00088 #endif 00089 00090 // For alternative platforms 00091 // 00092 #ifdef __macos__ 00093 #include <AvailabilityMacros.h> 00094 #ifndef POLLRDNORM 00095 #define POLLRDNORM 0 00096 #endif 00097 #ifndef POLLRDBAND 00098 #define POLLRDBAND 0 00099 #endif 00100 #ifndef POLLWRNORM 00101 #define POLLWRNORM 0 00102 #endif 00103 #define O_LARGEFILE 0 00104 #define memalign(pgsz,amt) valloc(amt) 00105 #define posix_memalign(memp, algn, sz) \ 00106 ((*memp = memalign(algn, sz)) ? 0 : ENOMEM) 00107 #define SHMDT_t void * 00108 #ifndef EDEADLOCK 00109 #define EDEADLOCK EDEADLK 00110 #endif 00111 #endif 00112 00113 #ifdef __FreeBSD__ 00114 #define O_LARGEFILE 0 00115 typedef off_t off64_t; 00116 #define memalign(pgsz,amt) valloc(amt) 00117 #endif 00118 00119 // Only sparc platforms have structure alignment problems w/ optimization 00120 // so the h2xxx() variants are used when converting network streams. 00121 00122 #if defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || \ 00123 defined(__IEEE_BIG_ENDIAN) || \ 00124 (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN) 00125 #define Xrd_Big_Endian 00126 #ifndef htonll 00127 #define htonll(_x_) _x_ 00128 #endif 00129 #ifndef h2nll 00130 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long)) 00131 #endif 00132 #ifndef ntohll 00133 #define ntohll(_x_) _x_ 00134 #endif 00135 #ifndef n2hll 00136 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long)) 00137 #endif 00138 00139 #elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || \ 00140 defined(__IEEE_LITTLE_ENDIAN) || \ 00141 (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) 00142 #if !defined(__GNUC__) || defined(__macos__) 00143 00144 #if !defined(__sun) || (defined(__sun) && (!defined(_LP64) || defined(__SunOS_5_10))) 00145 extern "C" unsigned long long Swap_n2hll(unsigned long long x); 00146 #ifndef htonll 00147 #define htonll(_x_) Swap_n2hll(_x_) 00148 #endif 00149 #ifndef ntohll 00150 #define ntohll(_x_) Swap_n2hll(_x_) 00151 #endif 00152 #endif 00153 00154 #else 00155 00156 #ifndef htonll 00157 #define htonll(_x_) __bswap_64(_x_) 00158 #endif 00159 #ifndef ntohll 00160 #define ntohll(_x_) __bswap_64(_x_) 00161 #endif 00162 00163 #endif 00164 00165 #ifndef h2nll 00166 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\ 00167 _y_ = htonll(_y_) 00168 #endif 00169 #ifndef n2hll 00170 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\ 00171 _y_ = ntohll(_y_) 00172 #endif 00173 00174 #else 00175 #ifndef WIN32 00176 #error Unable to determine target architecture endianness! 00177 #endif 00178 #endif 00179 00180 #ifndef HAVE_STRLCPY 00181 extern "C" 00182 {extern size_t strlcpy(char *dst, const char *src, size_t size);} 00183 #endif 00184 00185 // 00186 // To make socklen_t portable use SOCKLEN_t 00187 // 00188 #if defined(__solaris__) && !defined(__linux__) 00189 # if __GNUC__ >= 3 || __GNUC_MINOR__ >= 90 00190 # define XR__SUNGCC3 00191 # endif 00192 #endif 00193 #if defined(__linux__) 00194 # include <features.h> 00195 # if __GNU_LIBRARY__ == 6 00196 # ifndef XR__GLIBC 00197 # define XR__GLIBC 00198 # endif 00199 # endif 00200 #endif 00201 #if defined(__MACH__) && defined(__i386__) 00202 # define R__GLIBC 00203 #endif 00204 #if defined(_AIX) || \ 00205 (defined(XR__SUNGCC3) && !defined(__arch64__)) 00206 # define SOCKLEN_t size_t 00207 #elif defined(XR__GLIBC) || \ 00208 defined(__FreeBSD__) || \ 00209 (defined(XR__SUNGCC3) && defined(__arch64__)) || defined(__macos__) || \ 00210 (defined(__sun) && defined(_SOCKLEN_T)) 00211 # ifndef SOCKLEN_t 00212 # define SOCKLEN_t socklen_t 00213 # endif 00214 #elif !defined(SOCKLEN_t) 00215 # define SOCKLEN_t int 00216 #endif 00217 00218 #ifdef _LP64 00219 #define PTR2INT(x) static_cast<int>((long long)x) 00220 #else 00221 #define PTR2INT(x) int(x) 00222 #endif 00223 00224 #ifdef WIN32 00225 #include "XrdSys/XrdWin32.hh" 00226 #define Netdata_t void * 00227 #define Sokdata_t char * 00228 #define IOV_INIT(data,dlen) dlen,data 00229 #define MAKEDIR(path,mode) mkdir(path) 00230 #define net_errno WSAGetLastError() 00231 #else 00232 #define O_BINARY 0 00233 #define Netdata_t char * 00234 #define Sokdata_t void * 00235 #define IOV_INIT(data,dlen) data,dlen 00236 #define MAKEDIR(path,mode) mkdir(path,mode) 00237 #define net_errno errno 00238 #endif 00239 00240 #ifdef WIN32 00241 #define MAXNAMELEN 256 00242 #define MAXPATHLEN 1024 00243 #else 00244 #include <sys/param.h> 00245 #endif 00246 // The following gets arround a relative new gcc compiler bug 00247 // 00248 #define XRDABS(x) (x < 0 ? -x : x) 00249 00250 #ifndef LT_MODULE_EXT 00251 #define LT_MODULE_EXT ".so" 00252 #endif 00253 00254 #endif // __XRDSYS_PLATFORM_H__
1.7.5