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... 83 #if __GNUC__ < 3 || ( __GNUC__ == 3 && ( __GNUC_MINOR__ < 4 ) ) 85 #define __attribute__( x ) 89 #define __attribute__( x ) 99 #if defined( __linux ) || defined( __APPLE__ ) 100 void* mh = ::dlopen( name.
length() == 0 ?
nullptr :
path, RTLD_LAZY | RTLD_GLOBAL );
103 shl_t mh = ::shl_load( name.
length() == 0 ? 0 :
path, BIND_IMMEDIATE | BIND_VERBOSE, 0 );
104 HMODULE*
mod =
new HMODULE;
106 if ( 0 != ::shl_gethandle_r( mh, &mod->dsc ) ) {
109 typedef void* ( *___all )();
110 ___all _alloc = (___all)malloc;
111 mod->numSym = ::shl_getsymbols( mod->dsc.handle, TYPE_PROCEDURE, EXPORT_SYMBOLS, malloc, &mod->sym );
127 if ( name.
length() == 0 ) {
128 return doLoad( name, handle );
134 bool hasShlibSuffix =
false;
135 for (
const char* suffix : SHLIB_SUFFIXES ) {
136 const size_t len = strlen( suffix );
137 if ( dllName.
compare( dllName.
length() - len, len, suffix ) == 0 ) {
138 hasShlibSuffix =
true;
145 if ( !hasShlibSuffix ) {
146 dllName += SHLIB_SUFFIXES[0];
150 return doLoad( dllName, handle );
156 unsigned long res = 0;
158 if ( name.
length() == 0 ) {
159 res = loadWithoutEnvironment( name, handle );
164 if (
getEnv( name, imgName ) ) {
165 res = loadWithoutEnvironment( imgName, handle );
171 #if defined( __linux ) || defined( __APPLE__ ) 172 if ( ( dllName.
find(
'/' ) == std::string::npos ) && ( dllName.
compare( 0, 3,
"lib" ) != 0 ) ) {
173 dllName =
"lib" + dllName;
178 for (
const char* suffix : SHLIB_SUFFIXES ) {
181 const size_t len = strlen( suffix );
182 if ( dllName.
compare( dllName.
length() - len, len, suffix ) != 0 ) {
186 res = loadWithoutEnvironment( libName, handle );
194 #if defined( __linux ) || defined( __APPLE__ ) 207 if ( !::FreeLibrary( (HINSTANCE)handle ) ) {
208 #elif defined( __linux ) || defined( __APPLE__ ) 217 HMODULE*
mod = (HMODULE*)handle;
218 if ( 0 == ::shl_unload( mod->dsc.handle ) ) {
233 *pFunction = (
EntryPoint )::GetProcAddress( (HINSTANCE)handle, name.
data() );
234 if ( 0 == *pFunction ) {
238 #elif defined( __linux ) 239 *pFunction =
reinterpret_cast<EntryPoint>(::dlsym( handle, name.
c_str() ) );
246 #elif defined( __APPLE__ ) 248 if ( !( *pFunction ) ) {
253 if ( 0 == *pFunction ) {
261 HMODULE* mod = (HMODULE*)handle;
264 for (
int i = 0; i < mod->numSym; i++ ) {
265 long ll2 = strlen( mod->sym[i].name );
266 if ( 0 != ::strncmp( mod->sym[i].name, name.
c_str(), ( ll1 > ll2 ) ? ll1 : ll2 ) == 0 ) {
286 return ::GetLastError();
289 return static_cast<unsigned long>(
static_cast<unsigned int>( errno ) );
305 LPVOID lpMessageBuffer;
306 ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
307 MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
308 (LPTSTR)&lpMessageBuffer, 0, NULL );
309 errString = (
const char*)lpMessageBuffer;
311 ::LocalFree( lpMessageBuffer );
313 char* cerrString(
nullptr );
315 if ( error == 0xAFFEDEAD ) {
316 cerrString = (
char*)::dlerror();
317 if ( !cerrString ) cerrString = ::strerror( error );
319 cerrString = (
char*)
"Unknown error. No information found in strerror()!";
325 cerrString = ::strerror( error );
366 using namespace Gaudi;
401 return (
char**)&( args[0] );
407 #pragma warning( disable : 4996 ) 414 if ( ( env = getenv( var ) ) !=
nullptr ) {
425 if ( ( env = getenv( var ) ) !=
nullptr ) {
436 #if defined( __APPLE__ ) 438 #include "crt_externs.h" 442 #if defined( _WIN32 ) 443 #define environ _environ 444 #elif defined( __APPLE__ ) 445 static char** environ = *_NSGetEnviron();
448 for (
int i = 0; environ[i] !=
nullptr; ++i ) {
458 #include <execinfo.h> 466 int count = backtrace( addresses, depth );
467 return count > 0 ? count : 0;
469 #else // windows and osx parts not implemented 478 const int totalOffset = offset + 2;
479 const int totalDepth = depth + totalOffset;
485 for (
int i = totalOffset; i < count; ++i ) {
486 void* addr =
nullptr;
509 if ( dladdr( addresses, &info ) && info.dli_fname && info.dli_fname[0] !=
'\0' ) {
510 const char* symbol = info.dli_sname && info.dli_sname[0] !=
'\0' ? info.dli_sname :
nullptr;
512 lib = info.dli_fname;
513 addr = info.dli_saddr;
519 fnc = ( stat == 0 ) ? dmg.
get() : symbol;
528 #else // not implemented for windows and osx 538 return value.
empty() ?
540 ::unsetenv( name.
c_str() ),
543 ::setenv( name.
c_str(), value.
c_str(), overwrite );
546 if ( value.
empty() ) {
548 return ::_putenv( ( name +
"=" ).c_str() );
550 if ( !getenv( name.
c_str() ) || overwrite ) {
552 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.
Helper functions to set/get the application return code.
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.