13 #define SYSTEM_SYSTEM_CPP 31 #elif defined( __APPLE__ ) 33 #elif defined( _WIN32 ) 37 #define VCL_NAMESPACE Gaudi 42 # define strcasecmp _stricmp 43 # define strncasecmp _strnicmp 44 # define getpid _getpid 52 #else // UNIX...: first the EGCS stuff, then the OS dependent includes 54 # include "sys/times.h" 60 # if defined( __linux ) || defined( __APPLE__ ) 62 # include <sys/utsname.h> 71 # endif // HPUX or not... 79 #endif // Windows or Unix... 87 # if defined( __linux ) || defined( __APPLE__ ) 88 void* mh = ::dlopen(
name.length() == 0 ? nullptr :
path, RTLD_LAZY | RTLD_GLOBAL );
91 shl_t mh = ::shl_load(
name.length() == 0 ? 0 :
path, BIND_IMMEDIATE | BIND_VERBOSE, 0 );
92 HMODULE*
mod =
new HMODULE;
94 if ( 0 != ::shl_gethandle_r( mh, &
mod->dsc ) ) {
97 typedef void* ( *___all )();
98 ___all _alloc = (___all)malloc;
99 mod->numSym = ::shl_getsymbols(
mod->dsc.handle, TYPE_PROCEDURE, EXPORT_SYMBOLS, malloc, &
mod->sym );
112 if (
name.length() == 0 ) {
return doLoad(
name, handle ); }
117 bool hasShlibSuffix =
false;
118 for (
const char* suffix : SHLIB_SUFFIXES ) {
119 const size_t len =
strlen( suffix );
120 if ( dllName.
compare( dllName.
length() - len, len, suffix ) == 0 ) {
121 hasShlibSuffix =
true;
128 if ( !hasShlibSuffix ) { dllName += SHLIB_SUFFIXES[0]; }
131 return doLoad( dllName, handle );
136 unsigned long res = 0;
138 if (
name.length() == 0 ) {
139 res = loadWithoutEnvironment(
name, handle );
145 res = loadWithoutEnvironment( imgName, handle );
151 #if defined( __linux ) || defined( __APPLE__ ) 152 if ( ( dllName.
find(
'/' ) == std::string::npos ) && ( dllName.
compare( 0, 3,
"lib" ) != 0 ) ) {
153 dllName =
"lib" + dllName;
158 for (
const char* suffix : SHLIB_SUFFIXES ) {
161 const size_t len = strlen( suffix );
162 if ( dllName.
compare( dllName.
length() - len, len, suffix ) != 0 ) { libName += suffix; }
164 res = loadWithoutEnvironment( libName, handle );
166 if ( res == 1 ) {
break; }
170 #if defined( __linux ) || defined( __APPLE__ ) 182 if ( !::FreeLibrary( (HINSTANCE)handle ) ) {
183 #elif defined( __linux ) || defined( __APPLE__ ) 190 HMODULE*
mod = (HMODULE*)handle;
191 if ( 0 == ::shl_unload(
mod->dsc.handle ) ) {
205 *pFunction = (
EntryPoint )::GetProcAddress( (HINSTANCE)handle,
name.data() );
208 #elif defined( __linux ) 209 *pFunction = reinterpret_cast<EntryPoint>( ::dlsym( handle,
name.c_str() ) );
216 #elif defined( __APPLE__ ) 218 if ( !( *pFunction ) ) {
223 if ( 0 == *pFunction ) {
231 HMODULE*
mod = (HMODULE*)handle;
233 long ll1 =
name.length();
234 for (
int i = 0; i <
mod->numSym; i++ ) {
235 long ll2 = strlen(
mod->sym[i].name );
236 if ( 0 != ::strncmp(
mod->sym[i].name,
name.c_str(), ( ll1 > ll2 ) ? ll1 : ll2 ) == 0 ) {
254 return ::GetLastError();
257 return static_cast<unsigned long>( static_cast<unsigned int>( errno ) );
271 LPVOID lpMessageBuffer;
272 ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
273 MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
274 (LPTSTR)&lpMessageBuffer, 0, NULL );
275 errString = (
const char*)lpMessageBuffer;
277 ::LocalFree( lpMessageBuffer );
279 char* cerrString(
nullptr );
281 if ( error == 0xAFFEDEAD ) {
282 cerrString = ::dlerror();
283 if ( !cerrString ) cerrString = ::strerror( error );
285 cerrString = (
char*)
"Unknown error. No information found in strerror()!";
291 cerrString = ::strerror( error );
327 using namespace Gaudi;
359 return (
char**)&(
args[0] );
365 # pragma warning( disable : 4996 ) 371 if ( ( env = getenv( var ) ) !=
nullptr ) {
381 if ( ( env = getenv( var ) ) !=
nullptr ) {
392 #if defined( __APPLE__ ) 394 # include "crt_externs.h" 397 #if defined( _WIN32 ) 398 # define environ _environ 399 #elif defined( __APPLE__ ) 400 static char** environ = *_NSGetEnviron();
403 for (
int i = 0; environ[i] !=
nullptr; ++i ) { vars.
push_back( environ[i] ); }
411 # include <execinfo.h> 414 int System::backTrace( [[maybe_unused]]
void** addresses, [[maybe_unused]]
const int depth ) {
418 int count = backtrace( addresses, depth );
419 return count > 0 ? count : 0;
421 #else // windows and osx parts not implemented 429 const int totalOffset = offset + 2;
430 const int totalDepth = depth + totalOffset;
436 for (
int i = totalOffset; i < count; ++i ) {
437 void* addr =
nullptr;
457 if ( dladdr( addresses, &info ) && info.dli_fname && info.dli_fname[0] !=
'\0' ) {
458 const char* symbol = info.dli_sname && info.dli_sname[0] !=
'\0' ? info.dli_sname :
nullptr;
460 lib = info.dli_fname;
461 addr = info.dli_saddr;
467 fnc = ( stat == 0 ) ? dmg.get() : symbol;
476 #else // not implemented for windows and osx 485 return value.
empty() ?
487 ::unsetenv(
name.c_str() ),
490 ::setenv(
name.c_str(), value.
c_str(), overwrite );
493 if ( value.
empty() ) {
495 return ::_putenv( (
name +
"=" ).c_str() );
497 if ( !getenv(
name.c_str() ) || overwrite ) {
499 return ::_putenv( (
name +
"=" + value ).c_str() );
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
GAUDI_API long argc()
Number of arguments passed to the commandline (==numCmdLineArgs()); just to match argv call....
GAUDI_API char ** argv()
char** command line arguments including executable name as arg[0]; You may not modify them!
GAUDI_API const std::string getErrorString(unsigned long error)
Retrieve error code as string for a given error.
GAUDI_API int setEnv(const std::string &name, const std::string &value, int overwrite=1)
Set an environment variables.
GAUDI_API unsigned long getLastError()
Get last system known error.
GAUDI_API unsigned long getProcedureByName(ImageHandle handle, const std::string &name, EntryPoint *pFunction)
Get a specific function defined in the DLL.
GAUDI_API bool getStackLevel(void *addresses, void *&addr, std::string &fnc, std::string &lib)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
GAUDI_API int instructionsetLevel()
Instruction Set "Level".
GAUDI_API const std::string & accountName()
User login name.
void * ImageHandle
Definition of an image handle.
GAUDI_API int backTrace(void **addresses, const int depth)
GAUDI_API long numCmdLineArgs()
Number of arguments passed to the commandline.
GAUDI_API const std::string & exeName()
Name of the executable file running.
GAUDI_API const std::string & osName()
OS name.
int instrset_detect(void)
GAUDI_API unsigned long unloadDynamicLib(ImageHandle handle)
unload dynamic link library
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
GAUDI_API const std::string & hostName()
Host name.
void *(* Creator)()
Definition of the "generic" DLL entry point function.
T back_inserter(T... args)
GAUDI_API const std::vector< std::string > cmdLineArgs()
Command line arguments including executable name as arg[0] as vector of strings.
GAUDI_API const std::string & osVersion()
OS version.
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
GAUDI_API const std::string & machineType()
Machine type.
Header file for std:chrono::duration-based Counters.
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
unsigned long(* EntryPoint)(const unsigned long iid, void **ppvObject)
Definition of the "generic" DLL entry point function.