Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:42

0001 #ifndef __XRDSYS_PLATFORM_H__
0002 #define __XRDSYS_PLATFORM_H__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                     X r d S y s P l a t f o r m . h h                      */
0006 /*                                                                            */
0007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0009 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0010 /*                                                                            */
0011 /* This file is part of the XRootD software suite.                            */
0012 /*                                                                            */
0013 /* XRootD is free software: you can redistribute it and/or modify it under    */
0014 /* the terms of the GNU Lesser General Public License as published by the     */
0015 /* Free Software Foundation, either version 3 of the License, or (at your     */
0016 /* option) any later version.                                                 */
0017 /*                                                                            */
0018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0021 /* License for more details.                                                  */
0022 /*                                                                            */
0023 /* You should have received a copy of the GNU Lesser General Public License   */
0024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0026 /*                                                                            */
0027 /* The copyright holder's institutional names and contributor's names may not */
0028 /* be used to endorse or promote products derived from this software without  */
0029 /* specific prior written permission of the institution or contributor.       */
0030 /******************************************************************************/
0031 
0032 // Include stdlib so that ENDIAN macros are defined properly
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 // These are undefined on purpose in GNU/Hurd.
0083 // The values below are the ones used in Linux.
0084 // The proper fix is to rewrite the code to not use hardcoded values,
0085 // but instead allocate memory dynamically at runtime when sizes are known.
0086 // This is true also for systems where these constants are defined.
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 // The following provides historical support for Solaris 5.10.x
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   /* access mode bits */
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 // For alternative platforms
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 // Only sparc platforms have structure alignment problems w/ optimization
0181 // so the h2xxx() variants are used when converting network streams.
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 // To make socklen_t portable use SOCKLEN_t
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 // The following gets arround a relative new gcc compiler bug
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  // __XRDSYS_PLATFORM_H__