Skip to content

Commit

Permalink
Add new method to obtain a platform readable uname string.
Browse files Browse the repository at this point in the history
  • Loading branch information
abh3 committed Nov 26, 2013
1 parent f817eb0 commit 4999bf0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/XrdSys/XrdSysUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
Expand All @@ -48,6 +49,7 @@
#include <pwd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/utsname.h>
#endif
#include "XrdSysUtils.hh"

Expand Down Expand Up @@ -108,6 +110,36 @@ const char *XrdSysUtils::ExecName()
return "";
}

/******************************************************************************/
/* F m t U n a m e */
/******************************************************************************/

int XrdSysUtils::FmtUname(char *buff, int blen)
{
#if defined(WINDOWS)
return snprintf(buff, blen, "%s", "windows");
#else
struct utsname uInfo;

// Obtain the uname inofmormation
//
if (uname(&uInfo) < 0) return snprintf(buff, blen, "%s", "unknown OS");

// Format appropriate for certain platforms
// Linux and MacOs do not add usefull version information
//
#if defined(__linux__)
return snprintf(buff, blen, "%s %s", uInfo.sysname, uInfo.release);
#elif defined(__APPLE__) || defined(__FreeBSD__)
return snprintf(buff, blen, "%s %s %s", uInfo.sysname, uInfo.release,
uInfo.machine);
#else
return snprintf(buff, blen, "%s %s %s %s", uInfo.sysname, uInfo.release,
uInfo.version, uInfo.machine);
#endif
#endif
}

/******************************************************************************/
/* G e t S i g N u m */
/******************************************************************************/
Expand Down
12 changes: 12 additions & 0 deletions src/XrdSys/XrdSysUtils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ public:

static const char *ExecName();

//-----------------------------------------------------------------------------
//! Format the uname information
//!
//! @param buff - pointer to the buffer to hold the uname as:
//! <sysname> <release> [<version>] [<machine>]
//! @param blen - length of the buffer.
//!
//! @return the output of snprintf(buff, blen, ...);
//-----------------------------------------------------------------------------

static int FmtUname(char *buff, int blen);

//-----------------------------------------------------------------------------
//! Get common signal number.
//!
Expand Down

0 comments on commit 4999bf0

Please sign in to comment.