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 <cstdio>
31 #include <cstring>
32 #ifndef WIN32
33 #include <unistd.h>
34 #include <netinet/in.h>
35 #endif
36 #include <sys/types.h>
37 
38 #if defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || \
39  defined(__IEEE_LITTLE_ENDIAN) || \
40  (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)
41 #if !defined(__GNUC__) || defined(__APPLE__)
42 extern "C"
43 {
44 unsigned long long Swap_n2hll(unsigned long long x)
45 {
46  unsigned long long ret_val;
47  *( (unsigned int *)(&ret_val) + 1) = ntohl(*( (unsigned int *)(&x)));
48  *(((unsigned int *)(&ret_val))) = ntohl(*(((unsigned int *)(&x))+1));
49  return ret_val;
50 }
51 }
52 #endif
53 
54 #endif
55 
56 #ifndef HAVE_STRLCPY
57 extern "C"
58 {
59 size_t strlcpy(char *dst, const char *src, size_t sz)
60 {
61  size_t slen = strlen(src);
62  size_t tlen =sz-1;
63 
64  if (slen <= tlen) strcpy(dst, src);
65  else if (tlen > 0) {strncpy(dst, src, tlen); dst[tlen] = '\0';}
66  else if (tlen == 0) dst[0] = '\0';
67 
68  return slen;
69 }
70 }
71 #endif
size_t strlcpy(char *dst, const char *src, size_t sz)