XRootD
XrdSysPlatform.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d S y s P l a t f o r m . c c */
4 /* */
5 /* (c) 2006 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* Produced by Andrew Hanushevsky for Stanford University under contract */
7 /* DE-AC02-76-SFO0515 with the Department of Energy */
8 /* */
9 /* This file is part of the XRootD software suite. */
10 /* */
11 /* XRootD is free software: you can redistribute it and/or modify it under */
12 /* the terms of the GNU Lesser General Public License as published by the */
13 /* Free Software Foundation, either version 3 of the License, or (at your */
14 /* option) any later version. */
15 /* */
16 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19 /* License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24 /* */
25 /* The copyright holder's institutional names and contributor's names may not */
26 /* be used to endorse or promote products derived from this software without */
27 /* specific prior written permission of the institution or contributor. */
28 /******************************************************************************/
29 
30 #include <climits>
31 #include <cstdio>
32 #include <cstring>
33 #ifndef WIN32
34 #include <unistd.h>
35 #include <netinet/in.h>
36 #endif
37 #include <sys/types.h>
38 
39 #if defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || \
40  defined(__IEEE_LITTLE_ENDIAN) || \
41  (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)
42 #if !defined(__GNUC__) || defined(__APPLE__)
43 extern "C"
44 {
45 unsigned long long Swap_n2hll(unsigned long long x)
46 {
47  unsigned long long ret_val;
48  *( (unsigned int *)(&ret_val) + 1) = ntohl(*( (unsigned int *)(&x)));
49  *(((unsigned int *)(&ret_val))) = ntohl(*(((unsigned int *)(&x))+1));
50  return ret_val;
51 }
52 }
53 #endif
54 
55 #endif
56 
57 #ifndef HAVE_STRLCPY
58 extern "C"
59 {
60 size_t strlcpy(char *dst, const char *src, size_t sz)
61 {
62  size_t slen = strlen(src);
63  size_t tlen =sz-1;
64 
65  if (slen <= tlen) strcpy(dst, src);
66  else if (tlen > 0) {strncpy(dst, src, tlen); dst[tlen] = '\0';}
67  else if (tlen == 0) dst[0] = '\0';
68 
69  return slen;
70 }
71 }
72 #endif
73 
74 
75 namespace XrdSys {
76 
77 int getIovMax()
78 {
79 #ifndef IOV_MAX
80 #ifdef _SC_IOV_MAX
81  static int IOV_MAX = []() {
82  int sc_iov_max = sysconf(_SC_IOV_MAX);
83  return sc_iov_max > 0 ? sc_iov_max : 1024;
84  }();
85 #else
86 #define IOV_MAX 1024
87 #endif
88 #endif
89  return IOV_MAX;
90 }
91 
92 }
#define IOV_MAX
size_t strlcpy(char *dst, const char *src, size_t sz)
int getIovMax()