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