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