XrdSysPlatform.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                     X r d S y s P l a t f o r m . c c                      */
00004 /*                                                                            */
00005 /* (c) 2006 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010   
00011 //        $Id: XrdSysPlatform.cc 38011 2011-02-08 18:35:57Z ganis $
00012 
00013 const char *XrdSysPlatformCVSID = "$Id: XrdSysPlatform.cc 38011 2011-02-08 18:35:57Z ganis $";
00014 
00015 #include <stdio.h>
00016 #include <string.h>
00017 #ifndef WIN32
00018 #include <unistd.h>
00019 #include <netinet/in.h>
00020 #endif
00021 #include <sys/types.h>
00022 
00023 #if defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || \
00024     defined(__IEEE_LITTLE_ENDIAN) || \
00025    (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)
00026 #if !defined(__GNUC__) || defined(__macos__)
00027 extern "C"
00028 {
00029 unsigned long long Swap_n2hll(unsigned long long x)
00030 {
00031     unsigned long long ret_val;
00032     *( (unsigned int  *)(&ret_val) + 1) = ntohl(*( (unsigned int  *)(&x)));
00033     *(((unsigned int  *)(&ret_val)))    = ntohl(*(((unsigned int  *)(&x))+1));
00034     return ret_val;
00035 }
00036 }
00037 #endif
00038 
00039 #endif
00040 
00041 #ifndef HAVE_STRLCPY
00042 extern "C"
00043 {
00044 size_t strlcpy(char *dst, const char *src, size_t sz)
00045 {
00046     size_t slen = strlen(src);
00047     size_t tlen =sz-1;
00048 
00049     if (slen <= tlen) strcpy(dst, src);
00050        else if (tlen > 0) {strncpy(dst, src, tlen); dst[tlen] = '\0';}
00051                else if (tlen == 0) dst[0] = '\0';
00052 
00053     return slen;
00054 }
00055 }
00056 #endif
00057 #ifdef __macos__
00058 #include <pwd.h>
00059 // This is not re-enetrant or mt-safe but it's all we have
00060 //
00061 char *cuserid(char *buff)
00062 {
00063   static char myBuff[33];
00064   char *theBuff = (buff ? buff : myBuff);
00065 
00066   struct passwd *thePWD = getpwuid(getuid());
00067   if (!thePWD)
00068     {if (buff) *buff = '\0';
00069      return buff;
00070     }
00071 
00072   strlcpy(theBuff, thePWD->pw_name, 33);
00073   return theBuff;
00074 }
00075 #endif

Generated on Tue Jul 5 14:47:03 2011 for ROOT_528-00b_version by  doxygen 1.5.1