25 #include "sys/times.h" 31 #include <sys/utsname.h> 40 static std::string host =
"";
43 memset(buffer,0,
sizeof(buffer));
44 ::gethostname(buffer,
sizeof(buffer));
52 static std::string osname =
"";
54 if (uname(&ut) == 0) {
65 static std::string osver =
"";
67 if (uname(&ut) == 0) {
77 static std::string mach =
"";
79 if (uname(&ut) == 0) {
89 static std::string account =
"";
90 if ( account ==
"" ) {
91 const char* acct = ::getlogin();
92 if ( 0 == acct ) acct = ::getenv(
"LOGNAME");
93 if ( 0 == acct ) acct = ::getenv(
"USER");
94 account = (acct) ? acct :
"Unknown";
113 sprintf(exe,
"/proc/%d/cmdline", ::getpid());
114 FILE *cmdLine = ::fopen(exe,
"r");
117 long len = fread(cmd,
sizeof(
char),
sizeof(cmd), cmdLine);
120 for (
char* token = cmd; token-cmd < len; token += strlen(token)+1 ) {
145 if ( (env = getenv(var)) != 0 ) {
154 std::vector<std::string>
vars;
155 for (
int i=0;
environ[i] != 0; ++i) {
162 int System::setEnv(
const std::string &name,
const std::string &value,
int overwrite)
165 return value.empty() ?
167 ::unsetenv(name.c_str()) , 0 :
169 ::setenv(name.c_str(),value.c_str(), overwrite);
const std::string & machineType()
Machine type.
const std::vector< std::string > cmdLineArgs()
Command line arguments including executable name as arg[0] as vector of strings.
const std::string & osName()
OS name.
char ** argv()
char** command line arguments including executable name as arg[0]; You may not modify them! ...
const std::string & osVersion()
OS version.
static std::vector< const char * > s_argvChars
int setEnv(const std::string &name, const std::string &value, int overwrite=1)
set an environment variables.
const char * SHLIB_SUFFIX
long numCmdLineArgs()
Number of arguments passed to the commandline.
const std::string & exeName()
Name of the executable file running.
long argc()
Number of arguments passed to the commandline (==numCmdLineArgs()); just to match argv call...
static std::vector< std::string > s_argvStrings
const std::string & accountName()
User login name.
const std::string getEnv(const char *var)
get a particular environment variable
const std::string & hostName()
Host name.