File indexing completed on 2025-01-18 10:15:42
0001 #ifndef __XRDSYS_PLATFORM_H__
0002 #define __XRDSYS_PLATFORM_H__
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <cstdint>
0035 #include <cstdlib>
0036
0037 #ifdef __linux__
0038 #include <memory.h>
0039 #include <cstring>
0040 #include <sys/types.h>
0041 #include <sys/param.h>
0042 #include <byteswap.h>
0043 #define MAXNAMELEN NAME_MAX
0044 #endif
0045
0046 #ifdef __APPLE__
0047 #include <AvailabilityMacros.h>
0048 #include <sys/types.h>
0049 #include <sys/param.h>
0050 #include <libkern/OSByteOrder.h>
0051 #define fdatasync(x) fsync(x)
0052 #define MAXNAMELEN NAME_MAX
0053 #ifndef dirent64
0054 # define dirent64 dirent
0055 #endif
0056 #ifndef off64_t
0057 #define off64_t int64_t
0058 #endif
0059 #if (!defined(MAC_OS_X_VERSION_10_5) || \
0060 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
0061 #ifndef stat64
0062 # define stat64 stat
0063 #endif
0064 #endif
0065 #endif
0066
0067 #if defined(__FreeBSD__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
0068 #include <sys/types.h>
0069 #include <sys/param.h>
0070 #if defined(__FreeBSD__)
0071 #include <sys/endian.h>
0072 #else
0073 #include <byteswap.h>
0074 #endif
0075 #define MAXNAMELEN NAME_MAX
0076 #endif
0077
0078 #ifdef __GNU__
0079 #include <sys/types.h>
0080 #include <sys/param.h>
0081 #include <byteswap.h>
0082
0083
0084
0085
0086
0087 #define MAXNAMELEN 255
0088 #define MAXPATHLEN 4096
0089 #define MAXHOSTNAMELEN 64
0090 #endif
0091
0092 #ifdef WIN32
0093 #define MAXNAMELEN 256
0094 #define MAXPATHLEN 1024
0095 #endif
0096
0097
0098
0099 #if defined(__solaris__) && defined(__SunOS_5_10)
0100 #define posix_memalign(memp, algn, sz) \
0101 ((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
0102 #define __USE_LEGACY_PROTOTYPES__ 1
0103 #endif
0104
0105 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
0106
0107 #define S_IAMB 0x1FF
0108
0109 #define STATFS statfs
0110 #define STATFS_BUFF struct statfs
0111
0112 #define FS_BLKFACT 4
0113
0114 #define FLOCK_t struct flock
0115
0116 typedef off_t offset_t;
0117
0118 #define GTZ_NULL (struct timezone *)0
0119
0120 #else
0121
0122 #define STATFS statvfs
0123 #define STATFS_BUFF struct statvfs
0124
0125 #define FS_BLKFACT 1
0126
0127 #define SHMDT_t char *
0128
0129 #define FLOCK_t flock_t
0130
0131 #define GTZ_NULL (void *)0
0132
0133 #endif
0134
0135 #ifdef __linux__
0136
0137 #define SHMDT_t const void *
0138 #endif
0139
0140
0141
0142 #ifdef __APPLE__
0143 #ifndef POLLRDNORM
0144 #define POLLRDNORM 0
0145 #endif
0146 #ifndef POLLRDBAND
0147 #define POLLRDBAND 0
0148 #endif
0149 #ifndef POLLWRNORM
0150 #define POLLWRNORM 0
0151 #endif
0152 #define O_LARGEFILE 0
0153 #define SHMDT_t void *
0154 #ifndef EDEADLOCK
0155 #define EDEADLOCK EDEADLK
0156 #endif
0157 #endif
0158
0159 #ifdef __FreeBSD__
0160 #define O_LARGEFILE 0
0161 typedef off_t off64_t;
0162 #endif
0163
0164 #if defined(__APPLE__)
0165 #define bswap_16 OSSwapInt16
0166 #define bswap_32 OSSwapInt32
0167 #define bswap_64 OSSwapInt64
0168 #endif
0169
0170 #if defined(__FreeBSD__)
0171 #define bswap_16 bswap16
0172 #define bswap_32 bswap32
0173 #define bswap_64 bswap64
0174 #endif
0175
0176 static inline uint16_t bswap(uint16_t x) { return bswap_16(x); }
0177 static inline uint32_t bswap(uint32_t x) { return bswap_32(x); }
0178 static inline uint64_t bswap(uint64_t x) { return bswap_64(x); }
0179
0180
0181
0182
0183 #if defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || \
0184 defined(__IEEE_BIG_ENDIAN) || \
0185 (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN)
0186 #define Xrd_Big_Endian
0187 #ifndef htonll
0188 #define htonll(_x_) _x_
0189 #endif
0190 #ifndef h2nll
0191 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
0192 #endif
0193 #ifndef ntohll
0194 #define ntohll(_x_) _x_
0195 #endif
0196 #ifndef n2hll
0197 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
0198 #endif
0199
0200 #elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || \
0201 defined(__IEEE_LITTLE_ENDIAN) || \
0202 (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)
0203 #if !defined(__GNUC__) || defined(__APPLE__)
0204
0205 #if !defined(__sun) || (defined(__sun) && (!defined(_LP64) || defined(__SunOS_5_10)))
0206 extern "C" unsigned long long Swap_n2hll(unsigned long long x);
0207 #ifndef htonll
0208 #define htonll(_x_) Swap_n2hll(_x_)
0209 #endif
0210 #ifndef ntohll
0211 #define ntohll(_x_) Swap_n2hll(_x_)
0212 #endif
0213 #endif
0214
0215 #else
0216
0217 #ifndef htonll
0218 #define htonll(_x_) __bswap_64(_x_)
0219 #endif
0220 #ifndef ntohll
0221 #define ntohll(_x_) __bswap_64(_x_)
0222 #endif
0223
0224 #endif
0225
0226 #ifndef h2nll
0227 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
0228 _y_ = htonll(_y_)
0229 #endif
0230 #ifndef n2hll
0231 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
0232 _y_ = ntohll(_y_)
0233 #endif
0234
0235 #else
0236 #ifndef WIN32
0237 #error Unable to determine target architecture endianness!
0238 #endif
0239 #endif
0240
0241 #ifndef HAVE_STRLCPY
0242 extern "C"
0243 {extern size_t strlcpy(char *dst, const char *src, size_t size);}
0244 #endif
0245
0246
0247
0248
0249 #if defined(__solaris__) && !defined(__linux__)
0250 # if __GNUC__ >= 3 || __GNUC_MINOR__ >= 90
0251 # define XR__SUNGCC3
0252 # endif
0253 #endif
0254 #if defined(__linux__)
0255 # include <features.h>
0256 # if __GNU_LIBRARY__ == 6
0257 # ifndef XR__GLIBC
0258 # define XR__GLIBC
0259 # endif
0260 # endif
0261 #endif
0262 #if defined(__GNU__)
0263 # define XR__GLIBC
0264 #endif
0265 #if defined(_AIX) || \
0266 (defined(XR__SUNGCC3) && !defined(__arch64__))
0267 # define SOCKLEN_t size_t
0268 #elif !defined(SOCKLEN_t)
0269 # define SOCKLEN_t socklen_t
0270 #endif
0271
0272 #ifdef _LP64
0273 #define PTR2INT(x) static_cast<int>((long long)x)
0274 #else
0275 #define PTR2INT(x) int(x)
0276 #endif
0277
0278 #ifdef WIN32
0279 #include "XrdSys/XrdWin32.hh"
0280 #define Netdata_t void *
0281 #define Sokdata_t char *
0282 #define IOV_INIT(data,dlen) dlen,data
0283 #define MAKEDIR(path,mode) mkdir(path)
0284 #define CHMOD(path, mode) {}
0285 #define net_errno WSAGetLastError()
0286 #else
0287 #define O_BINARY 0
0288 #define Netdata_t char *
0289 #define Sokdata_t void *
0290 #define IOV_INIT(data,dlen) data,dlen
0291 #define MAKEDIR(path,mode) mkdir(path,mode)
0292 #define CHMOD(path, mode) chmod(path,mode)
0293 #define net_errno errno
0294 #endif
0295
0296
0297
0298 #define XRDABS(x) (x < 0 ? -x : x)
0299
0300 #ifndef LT_MODULE_EXT
0301 #define LT_MODULE_EXT ".so"
0302 #endif
0303
0304 #endif