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