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 <stdlib.h>
35 
36 #ifdef __linux__
37 #include <memory.h>
38 #include <string.h>
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <byteswap.h>
42 #define MAXNAMELEN NAME_MAX
43 #endif
44 
45 #ifdef __APPLE__
46 #include <AvailabilityMacros.h>
47 #include <sys/types.h>
48 #include <sys/param.h>
49 #define fdatasync(x) fsync(x)
50 #define MAXNAMELEN NAME_MAX
51 #ifndef dirent64
52 # define dirent64 dirent
53 #endif
54 #ifndef off64_t
55 #define off64_t int64_t
56 #endif
57 #if (!defined(MAC_OS_X_VERSION_10_5) || \
58  MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
59 #ifndef stat64
60 # define stat64 stat
61 #endif
62 #endif
63 #endif
64 
65 #if defined(__FreeBSD__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
66 #include <sys/types.h>
67 #include <sys/param.h>
68 #define MAXNAMELEN NAME_MAX
69 #endif
70 
71 #ifdef __GNU__
72 #include <sys/types.h>
73 #include <sys/param.h>
74 // These are undefined on purpose in GNU/Hurd.
75 // The values below are the ones used in Linux.
76 // The proper fix is to rewrite the code to not use hardcoded values,
77 // but instead allocate memory dynamically at runtime when sizes are known.
78 // This is true also for systems where these constants are defined.
79 #define MAXNAMELEN 255
80 #define MAXPATHLEN 4096
81 #define MAXHOSTNAMELEN 64
82 #endif
83 
84 #ifdef WIN32
85 #define MAXNAMELEN 256
86 #define MAXPATHLEN 1024
87 #endif
88 
89 #ifdef __solaris__
90 #define posix_memalign(memp, algn, sz) \
91  ((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
92 #define __USE_LEGACY_PROTOTYPES__ 1
93 #endif
94 
95 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
96 
97 #define S_IAMB 0x1FF /* access mode bits */
98 
99 #define STATFS statfs
100 #define STATFS_BUFF struct statfs
101 
102 #define FS_BLKFACT 4
103 
104 #define FLOCK_t struct flock
105 
106 typedef off_t offset_t;
107 
108 #define GTZ_NULL (struct timezone *)0
109 
110 #else
111 
112 #define STATFS statvfs
113 #define STATFS_BUFF struct statvfs
114 
115 #define FS_BLKFACT 1
116 
117 #define SHMDT_t char *
118 
119 #define FLOCK_t flock_t
120 
121 #define GTZ_NULL (void *)0
122 
123 #endif
124 
125 #ifdef __linux__
126 
127 #define SHMDT_t const void *
128 #endif
129 
130 // For alternative platforms
131 //
132 #ifdef __APPLE__
133 #ifndef POLLRDNORM
134 #define POLLRDNORM 0
135 #endif
136 #ifndef POLLRDBAND
137 #define POLLRDBAND 0
138 #endif
139 #ifndef POLLWRNORM
140 #define POLLWRNORM 0
141 #endif
142 #define O_LARGEFILE 0
143 #define memalign(pgsz,amt) valloc(amt)
144 #define posix_memalign(memp, algn, sz) \
145  ((*memp = memalign(algn, sz)) ? 0 : ENOMEM)
146 #define SHMDT_t void *
147 #ifndef EDEADLOCK
148 #define EDEADLOCK EDEADLK
149 #endif
150 #endif
151 
152 #ifdef __FreeBSD__
153 #define O_LARGEFILE 0
154 typedef off_t off64_t;
155 #define memalign(pgsz,amt) valloc(amt)
156 #endif
157 
158 // Only sparc platforms have structure alignment problems w/ optimization
159 // so the h2xxx() variants are used when converting network streams.
160 
161 #if defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || \
162  defined(__IEEE_BIG_ENDIAN) || \
163  (defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN)
164 #define Xrd_Big_Endian
165 #ifndef htonll
166 #define htonll(_x_) _x_
167 #endif
168 #ifndef h2nll
169 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
170 #endif
171 #ifndef ntohll
172 #define ntohll(_x_) _x_
173 #endif
174 #ifndef n2hll
175 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long))
176 #endif
177 
178 #elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || \
179  defined(__IEEE_LITTLE_ENDIAN) || \
180  (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)
181 #if !defined(__GNUC__) || defined(__APPLE__)
182 
183 #if !defined(__sun) || (defined(__sun) && (!defined(_LP64) || defined(__SunOS_5_10)))
184 extern "C" unsigned long long Swap_n2hll(unsigned long long x);
185 #ifndef htonll
186 #define htonll(_x_) Swap_n2hll(_x_)
187 #endif
188 #ifndef ntohll
189 #define ntohll(_x_) Swap_n2hll(_x_)
190 #endif
191 #endif
192 
193 #else
194 
195 #ifndef htonll
196 #define htonll(_x_) __bswap_64(_x_)
197 #endif
198 #ifndef ntohll
199 #define ntohll(_x_) __bswap_64(_x_)
200 #endif
201 
202 #endif
203 
204 #ifndef h2nll
205 #define h2nll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
206  _y_ = htonll(_y_)
207 #endif
208 #ifndef n2hll
209 #define n2hll(_x_, _y_) memcpy((void *)&_y_,(const void *)&_x_,sizeof(long long));\
210  _y_ = ntohll(_y_)
211 #endif
212 
213 #else
214 #ifndef WIN32
215 #error Unable to determine target architecture endianness!
216 #endif
217 #endif
218 
219 #ifndef HAVE_STRLCPY
220 extern "C"
221 {extern size_t strlcpy(char *dst, const char *src, size_t size);}
222 #endif
223 
224 //
225 // To make socklen_t portable use SOCKLEN_t
226 //
227 #if defined(__solaris__) && !defined(__linux__)
228 # if __GNUC__ >= 3 || __GNUC_MINOR__ >= 90
229 # define XR__SUNGCC3
230 # endif
231 #endif
232 #if defined(__linux__)
233 # include <features.h>
234 # if __GNU_LIBRARY__ == 6
235 # ifndef XR__GLIBC
236 # define XR__GLIBC
237 # endif
238 # endif
239 #endif
240 #if defined(__GNU__)
241 # define XR__GLIBC
242 #endif
243 #if defined(_AIX) || \
244  (defined(XR__SUNGCC3) && !defined(__arch64__))
245 # define SOCKLEN_t size_t
246 #elif defined(XR__GLIBC) || \
247  defined(__FreeBSD__) || \
248  (defined(__FreeBSD_kernel__) && defined(__GLIBC__)) || \
249  (defined(XR__SUNGCC3) && defined(__arch64__)) || defined(__APPLE__) || \
250  (defined(__sun) && defined(_SOCKLEN_T))
251 # ifndef SOCKLEN_t
252 # define SOCKLEN_t socklen_t
253 # endif
254 #elif !defined(SOCKLEN_t)
255 # define SOCKLEN_t int
256 #endif
257 
258 #ifdef _LP64
259 #define PTR2INT(x) static_cast<int>((long long)x)
260 #else
261 #define PTR2INT(x) int(x)
262 #endif
263 
264 #ifdef WIN32
265 #include "XrdSys/XrdWin32.hh"
266 #define Netdata_t void *
267 #define Sokdata_t char *
268 #define IOV_INIT(data,dlen) dlen,data
269 #define MAKEDIR(path,mode) mkdir(path)
270 #define CHMOD(path, mode) {}
271 #define net_errno WSAGetLastError()
272 #else
273 #define O_BINARY 0
274 #define Netdata_t char *
275 #define Sokdata_t void *
276 #define IOV_INIT(data,dlen) data,dlen
277 #define MAKEDIR(path,mode) mkdir(path,mode)
278 #define CHMOD(path, mode) chmod(path,mode)
279 #define net_errno errno
280 #endif
281 
282 // The following gets arround a relative new gcc compiler bug
283 //
284 #define XRDABS(x) (x < 0 ? -x : x)
285 
286 #ifndef LT_MODULE_EXT
287 #define LT_MODULE_EXT ".so"
288 #endif
289 
290 #endif // __XRDSYS_PLATFORM_H__
strlcpy
size_t strlcpy(char *dst, const char *src, size_t size)