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 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 // Include stdlib so that ENDIAN macros are defined properly
33 //
34 #include <cstdint>
35 #include <cstdlib>
36 
37 #ifdef __linux__
38 #include <memory.h>
39 #include <cstring>
40 #include <sys/types.h>
41 #include <sys/param.h>
42 #include <byteswap.h>
43 #define MAXNAMELEN NAME_MAX
44 #endif
45 
46 #ifdef __APPLE__
47 #include <AvailabilityMacros.h>
48 #include <sys/types.h>
49 #include <sys/param.h>
50 #include <libkern/OSByteOrder.h>
51 #define fdatasync(x) fsync(x)
52 #define MAXNAMELEN NAME_MAX
53 #ifndef dirent64
54 # define dirent64 dirent
55 #endif
56 #ifndef off64_t
57 #define off64_t int64_t
58 #endif
59 #if (!defined(MAC_OS_X_VERSION_10_5) || \
60  MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
61 #ifndef stat64
62 # define stat64 stat
63 #endif
64 #endif
65 #endif
66 
67 #if defined(__FreeBSD__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
68 #include <sys/types.h>
69 #include <sys/param.h>
70 #if defined(__FreeBSD__)
71 #include <sys/endian.h>
72 #else
73 #include <byteswap.h>
74 #endif
75 #define MAXNAMELEN NAME_MAX
76 #endif
77 
78 #ifdef __GNU__
79 #include <sys/types.h>
80 #include <sys/param.h>
81 #include <byteswap.h>
82 // These are undefined on purpose in GNU/Hurd.
83 // The values below are the ones used in Linux.
84 // The proper fix is to rewrite the code to not use hardcoded values,
85 // but instead allocate memory dynamically at runtime when sizes are known.
86 // This is true also for systems where these constants are defined.
87 #define MAXNAMELEN 255
88 #define MAXPATHLEN 4096
89 #define MAXHOSTNAMELEN 64
90 #endif
91 
92 #ifdef WIN32
93 #define MAXNAMELEN 256
94 #define MAXPATHLEN 1024
95 #endif
96 
97 // The following provides historical support for Solaris 5.10.x
98 //
99 #if defined(__solaris__) && defined(__SunOS_5_10)
100 #define posix_memalign(memp, algn, sz) \
101  ((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
102 #define __USE_LEGACY_PROTOTYPES__ 1
103 #endif
104 
105 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
106 
107 #define S_IAMB 0x1FF /* access mode bits */
108 
109 #define STATFS statfs
110 #define STATFS_BUFF struct statfs
111 
112 #define FS_BLKFACT 4
113 
114 #define FLOCK_t struct flock
115 
116 typedef off_t offset_t;
117 
118 #define GTZ_NULL (struct timezone *)0
119 
120 #else
121 
122 #define STATFS statvfs
123 #define STATFS_BUFF struct statvfs
124 
125 #define FS_BLKFACT 1
126 
127 #define SHMDT_t char *
128 
129 #define FLOCK_t flock_t
130 
131 #define GTZ_NULL (void *)0
132 
133 #endif
134 
135 #ifdef __linux__
136 
137 #define SHMDT_t const void *
138 #endif
139 
140 // For alternative platforms
141 //
142 #ifdef __APPLE__
143 #ifndef POLLRDNORM
144 #define POLLRDNORM 0
145 #endif
146 #ifndef POLLRDBAND
147 #define POLLRDBAND 0
148 #endif
149 #ifndef POLLWRNORM
150 #define POLLWRNORM 0
151 #endif
152 #define O_LARGEFILE 0
153 #define SHMDT_t void *
154 #ifndef EDEADLOCK
155 #define EDEADLOCK EDEADLK
156 #endif
157 #endif
158 
159 #ifdef __FreeBSD__
160 #define O_LARGEFILE 0
161 typedef off_t off64_t;
162 #endif
163 
164 #if defined(__APPLE__)
165 #define bswap_16 OSSwapInt16
166 #define bswap_32 OSSwapInt32
167 #define bswap_64 OSSwapInt64
168 #endif
169 
170 #if defined(__FreeBSD__)
171 #define bswap_16 bswap16
172 #define bswap_32 bswap32
173 #define bswap_64 bswap64
174 #endif
175 
176 static inline uint16_t bswap(uint16_t x) { return bswap_16(x); }
177 static inline uint32_t bswap(uint32_t x) { return bswap_32(x); }
178 static inline uint64_t bswap(uint64_t x) { return bswap_64(x); }
179 
180 // Only sparc platforms have structure alignment problems w/ optimization
181 // so the h2xxx() variants are used when converting network streams.
182 
183 #if defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || \
184  defined(__IEEE_BIG_ENDIAN) || \
185  (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN)
186 #define Xrd_Big_Endian
187 #ifndef htonll
188 #define htonll(_x_) _x_
189 #endif
190 #ifndef h2nll
191 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
192 #endif
193 #ifndef ntohll
194 #define ntohll(_x_) _x_
195 #endif
196 #ifndef n2hll
197 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
198 #endif
199 
200 #elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || \
201  defined(__IEEE_LITTLE_ENDIAN) || \
202  (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)
203 #if !defined(__GNUC__) || defined(__APPLE__)
204 
205 #if !defined(__sun) || (defined(__sun) && (!defined(_LP64) || defined(__SunOS_5_10)))
206 extern "C" unsigned long long Swap_n2hll(unsigned long long x);
207 #ifndef htonll
208 #define htonll(_x_) Swap_n2hll(_x_)
209 #endif
210 #ifndef ntohll
211 #define ntohll(_x_) Swap_n2hll(_x_)
212 #endif
213 #endif
214 
215 #else
216 
217 #ifndef htonll
218 #define htonll(_x_) __bswap_64(_x_)
219 #endif
220 #ifndef ntohll
221 #define ntohll(_x_) __bswap_64(_x_)
222 #endif
223 
224 #endif
225 
226 #ifndef h2nll
227 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
228  _y_ = htonll(_y_)
229 #endif
230 #ifndef n2hll
231 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
232  _y_ = ntohll(_y_)
233 #endif
234 
235 #else
236 #ifndef WIN32
237 #error Unable to determine target architecture endianness!
238 #endif
239 #endif
240 
241 #ifndef HAVE_STRLCPY
242 extern "C"
243 {extern size_t strlcpy(char *dst, const char *src, size_t size);}
244 #endif
245 
246 //
247 // To make socklen_t portable use SOCKLEN_t
248 //
249 #if defined(__solaris__) && !defined(__linux__)
250 # if __GNUC__ >= 3 || __GNUC_MINOR__ >= 90
251 # define XR__SUNGCC3
252 # endif
253 #endif
254 #if defined(__linux__)
255 # include <features.h>
256 # if __GNU_LIBRARY__ == 6
257 # ifndef XR__GLIBC
258 # define XR__GLIBC
259 # endif
260 # endif
261 #endif
262 #if defined(__GNU__)
263 # define XR__GLIBC
264 #endif
265 #if defined(_AIX) || \
266  (defined(XR__SUNGCC3) && !defined(__arch64__))
267 # define SOCKLEN_t size_t
268 #elif !defined(SOCKLEN_t)
269 # define SOCKLEN_t socklen_t
270 #endif
271 
272 #ifdef _LP64
273 #define PTR2INT(x) static_cast<int>((long long)x)
274 #else
275 #define PTR2INT(x) int(x)
276 #endif
277 
278 #ifdef WIN32
279 #include "XrdSys/XrdWin32.hh"
280 #define Netdata_t void *
281 #define Sokdata_t char *
282 #define IOV_INIT(data,dlen) dlen,data
283 #define MAKEDIR(path,mode) mkdir(path)
284 #define CHMOD(path, mode) {}
285 #define net_errno WSAGetLastError()
286 #else
287 #define O_BINARY 0
288 #define Netdata_t char *
289 #define Sokdata_t void *
290 #define IOV_INIT(data,dlen) data,dlen
291 #define MAKEDIR(path,mode) mkdir(path,mode)
292 #define CHMOD(path, mode) chmod(path,mode)
293 #define net_errno errno
294 #endif
295 
296 // The following gets arround a relative new gcc compiler bug
297 //
298 #define XRDABS(x) (x < 0 ? -x : x)
299 
300 #ifndef LT_MODULE_EXT
301 #define LT_MODULE_EXT ".so"
302 #endif
303 
304 namespace XrdSys {
305  //--------------------------------------------------------------------------
307  //--------------------------------------------------------------------------
308  int getIovMax();
309 }
310 
311 #endif // __XRDSYS_PLATFORM_H__
size_t strlcpy(char *dst, const char *src, size_t size)
static uint16_t bswap(uint16_t x)
int getIovMax()