xrootd
XrdSysPlatform.hh
Go to the documentation of this file.
1 #ifndef __XRDSYS_PLATFORM_H__
2 #define __XRDSYS_PLATFORM_H__
3 /******************************************************************************/
4 /* */
5 /* X r d S y s P l a t f o r m . h h */
6 /* */
7 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved. See XrdInfo.cc for complete License Terms */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 // $Id: XrdSysPlatform.hh 37681 2010-12-21 16:40:47Z rdm $
14 
15 // Include stdlib so that ENDIAN macros are defined properly
16 //
17 #include <stdlib.h>
18 #ifdef __linux__
19 #include <memory.h>
20 #include <string.h>
21 #include <sys/types.h>
22 #include <asm/param.h>
23 #include <byteswap.h>
24 #define MAXNAMELEN NAME_MAX
25 #endif
26 #ifdef __macos__
27 #include <AvailabilityMacros.h>
28 #include <sys/types.h>
29 #define fdatasync(x) fsync(x)
30 #define MAXNAMELEN NAME_MAX
31 #ifndef dirent64
32 # define dirent64 dirent
33 #endif
34 #ifndef off64_t
35 #define off64_t int64_t
36 #endif
37 #if (!defined(MAC_OS_X_VERSION_10_5) || \
38  MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
39 #ifndef stat64
40 # define stat64 stat
41 #endif
42 #endif
43 #endif
44 #ifdef __FreeBSD__
45 #include <sys/types.h>
46 #endif
47 
48 #ifdef __solaris__
49 #define posix_memalign(memp, algn, sz) \
50  ((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
51 #endif
52 
53 #if defined(__linux__) || defined(__macos__) || defined(__FreeBSD__)
54 
55 #define S_IAMB 0x1FF /* access mode bits */
56 
57 #define F_DUP2FD F_DUPFD
58 
59 #define STATFS statfs
60 #define STATFS_BUFF struct statfs
61 
62 #define FS_BLKFACT 4
63 
64 #define FLOCK_t struct flock
65 
66 typedef off_t offset_t;
67 
68 #define GTZ_NULL (struct timezone *)0
69 
70 #else
71 
72 #define STATFS statvfs
73 #define STATFS_BUFF struct statvfs
74 
75 #define FS_BLKFACT 1
76 
77 #define SHMDT_t char *
78 
79 #define FLOCK_t flock_t
80 
81 #define GTZ_NULL (void *)0
82 
83 #endif
84 
85 #ifdef __linux__
86 
87 #define SHMDT_t const void *
88 #endif
89 
90 // For alternative platforms
91 //
92 #ifdef __macos__
93 #include <AvailabilityMacros.h>
94 #ifndef POLLRDNORM
95 #define POLLRDNORM 0
96 #endif
97 #ifndef POLLRDBAND
98 #define POLLRDBAND 0
99 #endif
100 #ifndef POLLWRNORM
101 #define POLLWRNORM 0
102 #endif
103 #define O_LARGEFILE 0
104 #define memalign(pgsz,amt) valloc(amt)
105 #define posix_memalign(memp, algn, sz) \
106  ((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
107 #define SHMDT_t void *
108 #ifndef EDEADLOCK
109 #define EDEADLOCK EDEADLK
110 #endif
111 #endif
112 
113 #ifdef __FreeBSD__
114 #define O_LARGEFILE 0
115 typedef off_t off64_t;
116 #define memalign(pgsz,amt) valloc(amt)
117 #endif
118 
119 // Only sparc platforms have structure alignment problems w/ optimization
120 // so the h2xxx() variants are used when converting network streams.
121 
122 #if defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || \
123  defined(__IEEE_BIG_ENDIAN) || \
124  (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN)
125 #define Xrd_Big_Endian
126 #ifndef htonll
127 #define htonll(_x_) _x_
128 #endif
129 #ifndef h2nll
130 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
131 #endif
132 #ifndef ntohll
133 #define ntohll(_x_) _x_
134 #endif
135 #ifndef n2hll
136 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
137 #endif
138 
139 #elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || \
140  defined(__IEEE_LITTLE_ENDIAN) || \
141  (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)
142 #if !defined(__GNUC__) || defined(__macos__)
143 
144 #if !defined(__sun) || (defined(__sun) && (!defined(_LP64) || defined(__SunOS_5_10)))
145 extern "C" unsigned long long Swap_n2hll(unsigned long long x);
146 #ifndef htonll
147 #define htonll(_x_) Swap_n2hll(_x_)
148 #endif
149 #ifndef ntohll
150 #define ntohll(_x_) Swap_n2hll(_x_)
151 #endif
152 #endif
153 
154 #else
155 
156 #ifndef htonll
157 #define htonll(_x_) __bswap_64(_x_)
158 #endif
159 #ifndef ntohll
160 #define ntohll(_x_) __bswap_64(_x_)
161 #endif
162 
163 #endif
164 
165 #ifndef h2nll
166 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
167  _y_ = htonll(_y_)
168 #endif
169 #ifndef n2hll
170 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
171  _y_ = ntohll(_y_)
172 #endif
173 
174 #else
175 #ifndef WIN32
176 #error Unable to determine target architecture endianness!
177 #endif
178 #endif
179 
180 #ifndef HAVE_STRLCPY
181 extern "C"
182 {extern size_t strlcpy(char *dst, const char *src, size_t size);}
183 #endif
184 
185 //
186 // To make socklen_t portable use SOCKLEN_t
187 //
188 #if defined(__solaris__) && !defined(__linux__)
189 # if __GNUC__ >= 3 || __GNUC_MINOR__ >= 90
190 # define XR__SUNGCC3
191 # endif
192 #endif
193 #if defined(__linux__)
194 # include <features.h>
195 # if __GNU_LIBRARY__ == 6
196 # ifndef XR__GLIBC
197 # define XR__GLIBC
198 # endif
199 # endif
200 #endif
201 #if defined(__MACH__) && defined(__i386__)
202 # define R__GLIBC
203 #endif
204 #if defined(_AIX) || \
205  (defined(XR__SUNGCC3) && !defined(__arch64__))
206 # define SOCKLEN_t size_t
207 #elif defined(XR__GLIBC) || \
208  defined(__FreeBSD__) || \
209  (defined(XR__SUNGCC3) && defined(__arch64__)) || defined(__macos__) || \
210  (defined(__sun) && defined(_SOCKLEN_T))
211 # ifndef SOCKLEN_t
212 # define SOCKLEN_t socklen_t
213 # endif
214 #elif !defined(SOCKLEN_t)
215 # define SOCKLEN_t int
216 #endif
217 
218 #ifdef _LP64
219 #define PTR2INT(x) static_cast<int>((long long)x)
220 #else
221 #define PTR2INT(x) int(x)
222 #endif
223 
224 #ifdef WIN32
225 #include "XrdSys/XrdWin32.hh"
226 #define Netdata_t void *
227 #define Sokdata_t char *
228 #define IOV_INIT(data,dlen) dlen,data
229 #define MAKEDIR(path,mode) mkdir(path)
230 #define net_errno WSAGetLastError()
231 #else
232 #define O_BINARY 0
233 #define Netdata_t char *
234 #define Sokdata_t void *
235 #define IOV_INIT(data,dlen) data,dlen
236 #define MAKEDIR(path,mode) mkdir(path,mode)
237 #define net_errno errno
238 #endif
239 
240 #ifdef WIN32
241 #define MAXNAMELEN 256
242 #define MAXPATHLEN 1024
243 #else
244 #include <sys/param.h>
245 #endif
246 // The following gets arround a relative new gcc compiler bug
247 //
248 #define XRDABS(x) (x < 0 ? -x : x)
249 
250 #ifndef LT_MODULE_EXT
251 #define LT_MODULE_EXT ".so"
252 #endif
253 
254 #endif // __XRDSYS_PLATFORM_H__