Go to the documentation of this file.00001 #ifndef __XRDSYS_PLATFORM_H__
00002 #define __XRDSYS_PLATFORM_H__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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 #endif
00025 #ifdef __macos__
00026 #include <AvailabilityMacros.h>
00027 #include <sys/types.h>
00028 #define fdatasync(x) fsync(x)
00029 #ifndef dirent64
00030 # define dirent64 dirent
00031 #endif
00032 #ifndef off64_t
00033 #define off64_t int64_t
00034 #endif
00035 #if (!defined(MAC_OS_X_VERSION_10_5) || \
00036 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
00037 #ifndef stat64
00038 # define stat64 stat
00039 #endif
00040 #endif
00041 #endif
00042 #ifdef __FreeBSD__
00043 #include <sys/types.h>
00044 #endif
00045
00046 #ifdef __solaris__
00047 #define posix_memalign(memp, algn, sz) \
00048 ((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
00049 #endif
00050
00051 #if defined(__linux__) || defined(__macos__) || defined(__FreeBSD__)
00052
00053 #define S_IAMB 0x1FF
00054
00055 #define F_DUP2FD F_DUPFD
00056
00057 #define STATFS statfs
00058 #define STATFS_BUFF struct statfs
00059
00060 #define FS_BLKFACT 4
00061
00062 #define FLOCK_t struct flock
00063
00064 typedef off_t offset_t;
00065
00066 #define GTZ_NULL (struct timezone *)0
00067
00068 #else
00069
00070 #define STATFS statvfs
00071 #define STATFS_BUFF struct statvfs
00072
00073 #define FS_BLKFACT 1
00074
00075 #define SHMDT_t char *
00076
00077 #define FLOCK_t flock_t
00078
00079 #define GTZ_NULL (void *)0
00080
00081 #endif
00082
00083 #ifdef __linux__
00084
00085 #define SHMDT_t const void *
00086 #endif
00087
00088
00089
00090 #ifdef __macos__
00091 #include <AvailabilityMacros.h>
00092 extern char *cuserid(char *s);
00093 #ifndef POLLRDNORM
00094 #define POLLRDNORM 0
00095 #endif
00096 #ifndef POLLRDBAND
00097 #define POLLRDBAND 0
00098 #endif
00099 #ifndef POLLWRNORM
00100 #define POLLWRNORM 0
00101 #endif
00102 #define O_LARGEFILE 0
00103 #define memalign(pgsz,amt) valloc(amt)
00104 #define posix_memalign(memp, algn, sz) \
00105 ((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
00106 #define SHMDT_t void *
00107 #ifndef EDEADLOCK
00108 #define EDEADLOCK EDEADLK
00109 #endif
00110 #endif
00111
00112 #ifdef __FreeBSD__
00113 #define O_LARGEFILE 0
00114 typedef off_t off64_t;
00115 #define memalign(pgsz,amt) valloc(amt)
00116 #endif
00117
00118
00119
00120
00121 #if defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || \
00122 defined(__IEEE_BIG_ENDIAN) || \
00123 (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN)
00124 #define Xrd_Big_Endian
00125 #ifndef htonll
00126 #define htonll(_x_) _x_
00127 #endif
00128 #ifndef h2nll
00129 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
00130 #endif
00131 #ifndef ntohll
00132 #define ntohll(_x_) _x_
00133 #endif
00134 #ifndef n2hll
00135 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
00136 #endif
00137
00138 #elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || \
00139 defined(__IEEE_LITTLE_ENDIAN) || \
00140 (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)
00141 #if !defined(__GNUC__) || defined(__macos__)
00142
00143 extern "C" unsigned long long Swap_n2hll(unsigned long long x);
00144 #define htonll(_x_) Swap_n2hll(_x_)
00145 #define ntohll(_x_) Swap_n2hll(_x_)
00146
00147 #else
00148
00149 #ifndef htonll
00150 #define htonll(_x_) __bswap_64(_x_)
00151 #endif
00152 #ifndef ntohll
00153 #define ntohll(_x_) __bswap_64(_x_)
00154 #endif
00155
00156 #endif
00157
00158 #ifndef h2nll
00159 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
00160 _y_ = htonll(_y_)
00161 #endif
00162 #ifndef n2hll
00163 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
00164 _y_ = ntohll(_y_)
00165 #endif
00166
00167 #else
00168 #ifndef WIN32
00169 #error Unable to determine target architecture endianness!
00170 #endif
00171 #endif
00172
00173 #ifndef HAVE_STRLCPY
00174 extern "C"
00175 {extern size_t strlcpy(char *dst, const char *src, size_t size);}
00176 #endif
00177
00178
00179
00180
00181 #if defined(__solaris__) && !defined(__linux__)
00182 # if __GNUC__ >= 3 || __GNUC_MINOR__ >= 90
00183 # define XR__SUNGCC3
00184 # endif
00185 #endif
00186 #if defined(__linux__)
00187 # include <features.h>
00188 # if __GNU_LIBRARY__ == 6
00189 # ifndef XR__GLIBC
00190 # define XR__GLIBC
00191 # endif
00192 # endif
00193 #endif
00194 #if defined(__MACH__) && defined(__i386__)
00195 # define R__GLIBC
00196 #endif
00197 #if defined(_AIX) || \
00198 (defined(XR__SUNGCC3) && !defined(__arch64__))
00199 # define SOCKLEN_t size_t
00200 #elif defined(XR__GLIBC) || \
00201 defined(__FreeBSD__) || \
00202 (defined(XR__SUNGCC3) && defined(__arch64__)) || defined(__macos__)
00203 # ifndef SOCKLEN_t
00204 # define SOCKLEN_t socklen_t
00205 # endif
00206 #elif !defined(SOCKLEN_t)
00207 # define SOCKLEN_t int
00208 #endif
00209
00210 #ifdef _LP64
00211 #define PTR2INT(x) static_cast<int>((long long)x)
00212 #else
00213 #define PTR2INT(x) int(x)
00214 #endif
00215
00216 #ifdef WIN32
00217 #include "XrdSys/XrdWin32.hh"
00218 #define Netdata_t void *
00219 #define Sokdata_t char *
00220 #define IOV_INIT(data,dlen) dlen,data
00221 #define MAKEDIR(path,mode) mkdir(path)
00222 #define net_errno WSAGetLastError()
00223 #else
00224 #define O_BINARY 0
00225 #define Netdata_t char *
00226 #define Sokdata_t void *
00227 #define IOV_INIT(data,dlen) data,dlen
00228 #define MAKEDIR(path,mode) mkdir(path,mode)
00229 #define net_errno errno
00230 #endif
00231
00232
00233
00234 #define XRDABS(x) (x < 0 ? -x : x)
00235
00236 #endif // __XRDSYS_PLATFORM_H__