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