![[]](/images/special/trans.gif)
LibN2L-4 Library Code ReferenceClassesCompounds Files Members Method Index Full Reference system.cppGo to the documentation of this file.00001 #include "base/system.h" 00002 00003 #include "base/babelFish.h" 00004 00005 #include <sys/types.h> 00006 00007 #ifdef WIN32 00008 # define WIN32_LEAN_AND_MEAN 00009 # define STRICT 00010 # include <windows.h> 00011 #else 00012 # include <unistd.h> 00013 #endif 00014 00015 #include "base/cOutOfBoundsException.h" 00016 00017 namespace n2l 00018 { 00019 /********************************************************************/ 00020 const tUID n2lProcessUID() 00021 { 00022 # ifdef WIN32 00023 return tUID( 0 ); 00024 # else 00025 return tUID( getuid() ); 00026 # endif 00027 } 00028 00029 /********************************************************************/ 00030 const tUID n2lProcessGID() 00031 { 00032 # ifdef WIN32 00033 return tUID( 0 ); 00034 # else 00035 return tUID( getgid() ); 00036 # endif 00037 } 00038 00039 /********************************************************************/ 00040 const tBool n2lSetEnv( const tString &iName, 00041 const tString &iValue ) 00042 { 00043 # ifdef WIN32 00044 return SetEnvironmentVariableA( iName.c_str(), 00045 iValue.c_str() ); 00046 # else 00047 return (-1!=setenv( iName.c_str(), iValue.c_str(), 1 )); 00048 # endif 00049 } 00050 00051 /********************************************************************/ 00052 const tBool n2lUnsetEnv( const tString &iName ) 00053 { 00054 # ifdef WIN32 00055 return SetEnvironmentVariableA( iName.c_str(), 00056 NULL ); 00057 # else 00058 unsetenv( iName.c_str() ); 00059 # endif 00060 return true; 00061 } 00062 00063 /********************************************************************/ 00064 const tString n2lGetEnv( const tString &iName ) 00065 { 00066 # ifdef WIN32 00067 enum { n2lGetEnv_BUF_SIZE = 32767 }; 00068 char buf[n2lGetEnv_BUF_SIZE]; 00069 if (0 == GetEnvironmentVariableA( iName.c_str(), 00070 buf, n2lGetEnv_BUF_SIZE )) 00071 { 00072 tUint err; 00073 if ((err = GetLastError())==ERROR_ENVVAR_NOT_FOUND) 00074 throw cOutOfBoundsException( "n2lGetEnv", 00075 "No such environment variable", iName ); 00076 throw cException( "n2lGetEnv", "Something went wrong. " 00077 "Got error code: " + asString( err ) ); 00078 } 00079 return buf; 00080 # else 00081 char *tmp = getenv( iName.c_str() ); 00082 if (tmp==NULL) 00083 throw cOutOfBoundsException( "n2lGetEnv", 00084 "No such environment variable", iName ); 00085 return tmp; 00086 # endif 00087 } 00088 00089 00090 } |