XrdSysPlatform.hh

Go to the documentation of this file.
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 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00009 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00010 /*                                                                            */
00011 /* This file is part of the XRootD software suite.                            */
00012 /*                                                                            */
00013 /* XRootD is free software: you can redistribute it and/or modify it under    */
00014 /* the terms of the GNU Lesser General Public License as published by the     */
00015 /* Free Software Foundation, either version 3 of the License, or (at your     */
00016 /* option) any later version.                                                 */
00017 /*                                                                            */
00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00021 /* License for more details.                                                  */
00022 /*                                                                            */
00023 /* You should have received a copy of the GNU Lesser General Public License   */
00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00026 /*                                                                            */
00027 /* The copyright holder's institutional names and contributor's names may not */
00028 /* be used to endorse or promote products derived from this software without  */
00029 /* specific prior written permission of the institution or contributor.       */
00030 /******************************************************************************/
00031 
00032 // Include stdlib so that ENDIAN macros are defined properly
00033 //
00034 #include <stdlib.h>
00035 #ifdef __linux__
00036 #include <memory.h>
00037 #include <string.h>
00038 #include <sys/types.h>
00039 #include <asm/param.h>
00040 #include <byteswap.h>
00041 #define MAXNAMELEN NAME_MAX
00042 #endif
00043 #ifdef __APPLE__
00044 #include <AvailabilityMacros.h>
00045 #include <sys/types.h>
00046 #define fdatasync(x) fsync(x)
00047 #define MAXNAMELEN NAME_MAX
00048 #ifndef dirent64
00049 #  define dirent64 dirent
00050 #endif
00051 #ifndef off64_t
00052 #define off64_t int64_t
00053 #endif
00054 #if (!defined(MAC_OS_X_VERSION_10_5) || \
00055      MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
00056 #ifndef stat64
00057 #  define stat64 stat
00058 #endif
00059 #endif
00060 #endif
00061 #ifdef __FreeBSD__
00062 #include <sys/types.h>
00063 #endif
00064 
00065 #ifdef __solaris__
00066 #define posix_memalign(memp, algn, sz) \
00067         ((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
00068 #define __USE_LEGACY_PROTOTYPES__ 1
00069 #endif
00070 
00071 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
00072 
00073 #define S_IAMB      0x1FF   /* access mode bits */
00074 
00075 #define F_DUP2FD F_DUPFD
00076 
00077 #define STATFS      statfs
00078 #define STATFS_BUFF struct statfs
00079 
00080 #define FS_BLKFACT  4
00081 
00082 #define FLOCK_t struct flock
00083 
00084 typedef off_t offset_t;
00085 
00086 #define GTZ_NULL (struct timezone *)0
00087 
00088 #else
00089 
00090 #define STATFS      statvfs
00091 #define STATFS_BUFF struct statvfs
00092 
00093 #define FS_BLKFACT  1
00094 
00095 #define SHMDT_t char *
00096 
00097 #define FLOCK_t flock_t
00098 
00099 #define GTZ_NULL (void *)0
00100 
00101 #endif
00102 
00103 #ifdef __linux__
00104 
00105 #define SHMDT_t const void *
00106 #endif
00107 
00108 // For alternative platforms
00109 //
00110 #ifdef __APPLE__
00111 #include <AvailabilityMacros.h>
00112 #ifndef POLLRDNORM
00113 #define POLLRDNORM  0
00114 #endif
00115 #ifndef POLLRDBAND
00116 #define POLLRDBAND  0
00117 #endif
00118 #ifndef POLLWRNORM
00119 #define POLLWRNORM  0
00120 #endif
00121 #define O_LARGEFILE 0
00122 #define memalign(pgsz,amt) valloc(amt)
00123 #define posix_memalign(memp, algn, sz) \
00124         ((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
00125 #define SHMDT_t void *
00126 #ifndef EDEADLOCK
00127 #define EDEADLOCK EDEADLK
00128 #endif
00129 #endif
00130 
00131 #ifdef __FreeBSD__
00132 #define O_LARGEFILE 0
00133 typedef off_t off64_t;
00134 #define memalign(pgsz,amt) valloc(amt)
00135 #endif
00136 
00137 // Only sparc platforms have structure alignment problems w/ optimization
00138 // so the h2xxx() variants are used when converting network streams.
00139 
00140 #if defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || \
00141    defined(__IEEE_BIG_ENDIAN) || \
00142    (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN)
00143 #define Xrd_Big_Endian
00144 #ifndef htonll
00145 #define htonll(_x_)  _x_
00146 #endif
00147 #ifndef h2nll
00148 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
00149 #endif
00150 #ifndef ntohll
00151 #define ntohll(_x_)  _x_
00152 #endif
00153 #ifndef n2hll
00154 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
00155 #endif
00156 
00157 #elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || \
00158      defined(__IEEE_LITTLE_ENDIAN) || \
00159      (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)
00160 #if !defined(__GNUC__) || defined(__APPLE__)
00161 
00162 #if !defined(__sun) || (defined(__sun) && (!defined(_LP64) || defined(__SunOS_5_10)))
00163 extern "C" unsigned long long Swap_n2hll(unsigned long long x);
00164 #ifndef htonll
00165 #define htonll(_x_) Swap_n2hll(_x_)
00166 #endif
00167 #ifndef ntohll
00168 #define ntohll(_x_) Swap_n2hll(_x_)
00169 #endif
00170 #endif
00171 
00172 #else
00173 
00174 #ifndef htonll
00175 #define htonll(_x_) __bswap_64(_x_)
00176 #endif
00177 #ifndef ntohll
00178 #define ntohll(_x_) __bswap_64(_x_)
00179 #endif
00180 
00181 #endif
00182 
00183 #ifndef h2nll
00184 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
00185                         _y_ = htonll(_y_)
00186 #endif
00187 #ifndef n2hll
00188 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
00189                         _y_ = ntohll(_y_)
00190 #endif
00191 
00192 #else
00193 #ifndef WIN32
00194 #error Unable to determine target architecture endianness!
00195 #endif
00196 #endif
00197 
00198 #ifndef HAVE_STRLCPY
00199 extern "C"
00200 {extern size_t strlcpy(char *dst, const char *src, size_t size);}
00201 #endif
00202 
00203 //
00204 // To make socklen_t portable use SOCKLEN_t
00205 //
00206 #if defined(__solaris__) && !defined(__linux__)
00207 #   if __GNUC__ >= 3 || __GNUC_MINOR__ >= 90
00208 #      define XR__SUNGCC3
00209 #   endif
00210 #endif
00211 #if defined(__linux__)
00212 #   include <features.h>
00213 #   if __GNU_LIBRARY__ == 6
00214 #      ifndef XR__GLIBC
00215 #         define XR__GLIBC
00216 #      endif
00217 #   endif
00218 #endif
00219 #if defined(__MACH__) && defined(__i386__)
00220 #   define R__GLIBC
00221 #endif
00222 #if defined(_AIX) || \
00223    (defined(XR__SUNGCC3) && !defined(__arch64__))
00224 #   define SOCKLEN_t size_t
00225 #elif defined(XR__GLIBC) || \
00226    defined(__FreeBSD__) || \
00227    (defined(XR__SUNGCC3) && defined(__arch64__)) || defined(__APPLE__) || \
00228    (defined(__sun) && defined(_SOCKLEN_T))
00229 #   ifndef SOCKLEN_t
00230 #      define SOCKLEN_t socklen_t
00231 #   endif
00232 #elif !defined(SOCKLEN_t)
00233 #   define SOCKLEN_t int
00234 #endif
00235 
00236 #ifdef _LP64
00237 #define PTR2INT(x) static_cast<int>((long long)x)
00238 #else
00239 #define PTR2INT(x) int(x)
00240 #endif
00241 
00242 #ifdef WIN32
00243 #include "XrdSys/XrdWin32.hh"
00244 #define Netdata_t void *
00245 #define Sokdata_t char *
00246 #define IOV_INIT(data,dlen) dlen,data
00247 #define MAKEDIR(path,mode) mkdir(path)
00248 #define net_errno WSAGetLastError()
00249 #else
00250 #define O_BINARY 0
00251 #define Netdata_t char *
00252 #define Sokdata_t void *
00253 #define IOV_INIT(data,dlen) data,dlen
00254 #define MAKEDIR(path,mode) mkdir(path,mode)
00255 #define net_errno errno
00256 #endif
00257 
00258 #ifdef WIN32
00259 #define MAXNAMELEN 256
00260 #define MAXPATHLEN 1024
00261 #else
00262 #include <sys/param.h>
00263 #endif
00264 // The following gets arround a relative new gcc compiler bug
00265 //
00266 #define XRDABS(x) (x < 0 ? -x : x)
00267 
00268 #ifndef LT_MODULE_EXT
00269 #define LT_MODULE_EXT ".so"
00270 #endif
00271 
00272 #endif  // __XRDSYS_PLATFORM_H__

Generated on 16 Jan 2014 for xrootd by  doxygen 1.4.7