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 #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
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
00091
00092 #ifdef __macos__
00093 #include <AvailabilityMacros.h>
00094 extern char *cuserid(char *s);
00095 #ifndef POLLRDNORM
00096 #define POLLRDNORM 0
00097 #endif
00098 #ifndef POLLRDBAND
00099 #define POLLRDBAND 0
00100 #endif
00101 #ifndef POLLWRNORM
00102 #define POLLWRNORM 0
00103 #endif
00104 #define O_LARGEFILE 0
00105 #define memalign(pgsz,amt) valloc(amt)
00106 #define posix_memalign(memp, algn, sz) \
00107 ((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
00108 #define SHMDT_t void *
00109 #ifndef EDEADLOCK
00110 #define EDEADLOCK EDEADLK
00111 #endif
00112 #endif
00113
00114 #ifdef __FreeBSD__
00115 #define O_LARGEFILE 0
00116 typedef off_t off64_t;
00117 #define memalign(pgsz,amt) valloc(amt)
00118 #endif
00119
00120
00121
00122
00123 #if defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || \
00124 defined(__IEEE_BIG_ENDIAN) || \
00125 (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN)
00126 #define Xrd_Big_Endian
00127 #ifndef htonll
00128 #define htonll(_x_) _x_
00129 #endif
00130 #ifndef h2nll
00131 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
00132 #endif
00133 #ifndef ntohll
00134 #define ntohll(_x_) _x_
00135 #endif
00136 #ifndef n2hll
00137 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
00138 #endif
00139
00140 #elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || \
00141 defined(__IEEE_LITTLE_ENDIAN) || \
00142 (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)
00143 #if !defined(__GNUC__) || defined(__macos__)
00144
00145 extern "C" unsigned long long Swap_n2hll(unsigned long long x);
00146 #define htonll(_x_) Swap_n2hll(_x_)
00147 #define ntohll(_x_) Swap_n2hll(_x_)
00148
00149 #else
00150
00151 #ifndef htonll
00152 #define htonll(_x_) __bswap_64(_x_)
00153 #endif
00154 #ifndef ntohll
00155 #define ntohll(_x_) __bswap_64(_x_)
00156 #endif
00157
00158 #endif
00159
00160 #ifndef h2nll
00161 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
00162 _y_ = htonll(_y_)
00163 #endif
00164 #ifndef n2hll
00165 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
00166 _y_ = ntohll(_y_)
00167 #endif
00168
00169 #else
00170 #ifndef WIN32
00171 #error Unable to determine target architecture endianness!
00172 #endif
00173 #endif
00174
00175 #ifndef HAVE_STRLCPY
00176 extern "C"
00177 {extern size_t strlcpy(char *dst, const char *src, size_t size);}
00178 #endif
00179
00180
00181
00182
00183 #if defined(__solaris__) && !defined(__linux__)
00184 # if __GNUC__ >= 3 || __GNUC_MINOR__ >= 90
00185 # define XR__SUNGCC3
00186 # endif
00187 #endif
00188 #if defined(__linux__)
00189 # include <features.h>
00190 # if __GNU_LIBRARY__ == 6
00191 # ifndef XR__GLIBC
00192 # define XR__GLIBC
00193 # endif
00194 # endif
00195 #endif
00196 #if defined(__MACH__) && defined(__i386__)
00197 # define R__GLIBC
00198 #endif
00199 #if defined(_AIX) || \
00200 (defined(XR__SUNGCC3) && !defined(__arch64__))
00201 # define SOCKLEN_t size_t
00202 #elif defined(XR__GLIBC) || \
00203 defined(__FreeBSD__) || \
00204 (defined(XR__SUNGCC3) && defined(__arch64__)) || defined(__macos__)
00205 # ifndef SOCKLEN_t
00206 # define SOCKLEN_t socklen_t
00207 # endif
00208 #elif !defined(SOCKLEN_t)
00209 # define SOCKLEN_t int
00210 #endif
00211
00212 #ifdef _LP64
00213 #define PTR2INT(x) static_cast<int>((long long)x)
00214 #else
00215 #define PTR2INT(x) int(x)
00216 #endif
00217
00218 #ifdef WIN32
00219 #include "XrdSys/XrdWin32.hh"
00220 #define Netdata_t void *
00221 #define Sokdata_t char *
00222 #define IOV_INIT(data,dlen) dlen,data
00223 #define MAKEDIR(path,mode) mkdir(path)
00224 #define net_errno WSAGetLastError()
00225 #else
00226 #define O_BINARY 0
00227 #define Netdata_t char *
00228 #define Sokdata_t void *
00229 #define IOV_INIT(data,dlen) data,dlen
00230 #define MAKEDIR(path,mode) mkdir(path,mode)
00231 #define net_errno errno
00232 #endif
00233
00234 #ifdef WIN32
00235 #define MAXNAMELEN 256
00236 #define MAXPATHLEN 1024
00237 #else
00238 #include <sys/param.h>
00239 #endif
00240
00241
00242 #define XRDABS(x) (x < 0 ? -x : x)
00243
00244 #endif // __XRDSYS_PLATFORM_H__