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