23 #define SYSTEM_SYSTEM_CPP
41 #elif defined( __APPLE__ )
43 #elif defined( _WIN32 )
47 #define VCL_NAMESPACE Gaudi
52 # define strcasecmp _stricmp
53 # define strncasecmp _strnicmp
54 # define getpid _getpid
62 #else // UNIX...: first the EGCS stuff, then the OS dependent includes
64 # include "sys/times.h"
70 # if defined( __linux ) || defined( __APPLE__ )
72 # include <sys/utsname.h>
81 # endif // HPUX or not...
89 #endif // Windows or Unix...
97 # if defined( __linux ) || defined( __APPLE__ )
98 void* mh = ::dlopen(
name.length() == 0 ?
nullptr :
path, RTLD_LAZY | RTLD_GLOBAL );
101 shl_t mh = ::shl_load(
name.length() == 0 ? 0 :
path, BIND_IMMEDIATE | BIND_VERBOSE, 0 );
102 HMODULE*
mod =
new HMODULE;
104 if ( 0 != ::shl_gethandle_r( mh, &
mod->dsc ) ) {
107 typedef void* ( *___all )();
108 ___all _alloc = (___all)malloc;
109 mod->numSym = ::shl_getsymbols(
mod->dsc.handle, TYPE_PROCEDURE, EXPORT_SYMBOLS, malloc, &
mod->sym );
122 if (
name.length() == 0 ) {
return doLoad(
name, handle ); }
127 bool hasShlibSuffix =
false;
128 for (
const char* suffix : SHLIB_SUFFIXES ) {
129 const size_t len =
strlen( suffix );
130 if ( dllName.
compare( dllName.
length() - len, len, suffix ) == 0 ) {
131 hasShlibSuffix =
true;
138 if ( !hasShlibSuffix ) { dllName += SHLIB_SUFFIXES[0]; }
141 return doLoad( dllName, handle );
146 unsigned long res = 0;
148 if (
name.length() == 0 ) {
149 res = loadWithoutEnvironment(
name, handle );
155 res = loadWithoutEnvironment( imgName, handle );
161 #if defined( __linux ) || defined( __APPLE__ )
162 if ( ( dllName.
find(
'/' ) == std::string::npos ) && ( dllName.
compare( 0, 3,
"lib" ) != 0 ) ) {
163 dllName =
"lib" + dllName;
168 for (
const char* suffix : SHLIB_SUFFIXES ) {
171 const size_t len = strlen( suffix );
172 if ( dllName.
compare( dllName.
length() - len, len, suffix ) != 0 ) { libName += suffix; }
174 res = loadWithoutEnvironment( libName, handle );
176 if ( res == 1 ) {
break; }
180 #if defined( __linux ) || defined( __APPLE__ )
192 if ( !::FreeLibrary( (HINSTANCE)handle ) ) {
193 #elif defined( __linux ) || defined( __APPLE__ )
200 HMODULE*
mod = (HMODULE*)handle;
201 if ( 0 == ::shl_unload(
mod->dsc.handle ) ) {
215 *pFunction = (
EntryPoint )::GetProcAddress( (HINSTANCE)handle,
name.data() );
218 #elif defined( __linux )
219 *pFunction =
reinterpret_cast<EntryPoint>( ::dlsym( handle,
name.c_str() ) );
226 #elif defined( __APPLE__ )
228 if ( !( *pFunction ) ) {
233 if ( 0 == *pFunction ) {
241 HMODULE*
mod = (HMODULE*)handle;
243 long ll1 =
name.length();
244 for (
int i = 0; i <
mod->numSym; i++ ) {
245 long ll2 = strlen(
mod->sym[i].name );
246 if ( 0 != ::strncmp(
mod->sym[i].name,
name.c_str(), ( ll1 > ll2 ) ? ll1 : ll2 ) == 0 ) {
264 return ::GetLastError();
267 return static_cast<unsigned long>(
static_cast<unsigned int>( errno ) );
281 LPVOID lpMessageBuffer;
282 ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
283 MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
284 (LPTSTR)&lpMessageBuffer, 0, NULL );
285 errString = (
const char*)lpMessageBuffer;
287 ::LocalFree( lpMessageBuffer );
289 char* cerrString(
nullptr );
291 if ( error == 0xAFFEDEAD ) {
292 cerrString = ::dlerror();
293 if ( !cerrString ) cerrString = ::strerror( error );
295 cerrString = (
char*)
"Unknown error. No information found in strerror()!";
301 cerrString = ::strerror( error );
337 using namespace Gaudi;
369 return (
char**)&(
args[0] );
375 # pragma warning( disable : 4996 )
381 if ( ( env = getenv( var ) ) !=
nullptr ) {
391 if ( ( env = getenv( var ) ) !=
nullptr ) {
402 #if defined( __APPLE__ )
404 # include "crt_externs.h"
407 #if defined( _WIN32 )
408 # define environ _environ
409 #elif defined( __APPLE__ )
410 static char** environ = *_NSGetEnviron();
413 for (
int i = 0; environ[i] !=
nullptr; ++i ) { vars.
push_back( environ[i] ); }
421 # include <execinfo.h>
424 int System::backTrace( [[maybe_unused]]
void** addresses, [[maybe_unused]]
const int depth ) {
428 int count = backtrace( addresses, depth );
429 return count > 0 ? count : 0;
431 #else // windows and osx parts not implemented
439 const int totalOffset = offset + 2;
440 const int totalDepth = depth + totalOffset;
446 for (
int i = totalOffset; i < count; ++i ) {
447 void* addr =
nullptr;
467 if ( dladdr( addresses, &info ) && info.dli_fname && info.dli_fname[0] !=
'\0' ) {
468 const char* symbol = info.dli_sname && info.dli_sname[0] !=
'\0' ? info.dli_sname :
nullptr;
470 lib = info.dli_fname;
471 addr = info.dli_saddr;
477 fnc = ( stat == 0 ) ? dmg.get() : symbol;
486 #else // not implemented for windows and osx
495 return value.
empty() ?
497 ::unsetenv(
name.c_str() ),
500 ::setenv(
name.c_str(), value.
c_str(), overwrite );
503 if ( value.
empty() ) {
505 return ::_putenv( (
name +
"=" ).c_str() );
507 if ( !getenv(
name.c_str() ) || overwrite ) {
509 return ::_putenv( (
name +
"=" + value ).c_str() );