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 ) 98 # if defined( __linux ) || defined( __APPLE__ ) 99 void* mh = ::dlopen( name.
length() == 0 ?
nullptr :
path, RTLD_LAZY | RTLD_GLOBAL );
102 shl_t mh = ::shl_load( name.
length() == 0 ? 0 :
path, BIND_IMMEDIATE | BIND_VERBOSE, 0 );
103 HMODULE*
mod =
new HMODULE;
105 if ( 0 != ::shl_gethandle_r( mh, &mod->dsc ) ) {
108 typedef void* ( *___all )();
109 ___all _alloc = (___all)malloc;
110 mod->numSym = ::shl_getsymbols( mod->dsc.handle, TYPE_PROCEDURE, EXPORT_SYMBOLS, malloc, &mod->sym );
123 if ( name.
length() == 0 ) {
return doLoad( name, handle ); }
128 bool hasShlibSuffix =
false;
129 for (
const char* suffix : SHLIB_SUFFIXES ) {
130 const size_t len = strlen( suffix );
131 if ( dllName.
compare( dllName.
length() - len, len, suffix ) == 0 ) {
132 hasShlibSuffix =
true;
139 if ( !hasShlibSuffix ) { dllName += SHLIB_SUFFIXES[0]; }
142 return doLoad( dllName, handle );
147 unsigned long res = 0;
149 if ( name.
length() == 0 ) {
150 res = loadWithoutEnvironment( name, handle );
155 if (
getEnv( name, imgName ) ) {
156 res = loadWithoutEnvironment( imgName, handle );
162 #if defined( __linux ) || defined( __APPLE__ ) 163 if ( ( dllName.
find(
'/' ) == std::string::npos ) && ( dllName.
compare( 0, 3,
"lib" ) != 0 ) ) {
164 dllName =
"lib" + dllName;
169 for (
const char* suffix : SHLIB_SUFFIXES ) {
172 const size_t len = strlen( suffix );
173 if ( dllName.
compare( dllName.
length() - len, len, suffix ) != 0 ) { libName += suffix; }
175 res = loadWithoutEnvironment( libName, handle );
177 if ( res == 1 ) {
break; }
181 #if defined( __linux ) || defined( __APPLE__ ) 193 if ( !::FreeLibrary( (HINSTANCE)handle ) ) {
194 #elif defined( __linux ) || defined( __APPLE__ ) 201 HMODULE*
mod = (HMODULE*)handle;
202 if ( 0 == ::shl_unload( mod->dsc.handle ) ) {
216 *pFunction = (
EntryPoint )::GetProcAddress( (HINSTANCE)handle, name.
data() );
219 #elif defined( __linux ) 220 *pFunction =
reinterpret_cast<EntryPoint>( ::dlsym( handle, name.
c_str() ) );
227 #elif defined( __APPLE__ ) 229 if ( !( *pFunction ) ) {
234 if ( 0 == *pFunction ) {
242 HMODULE* mod = (HMODULE*)handle;
245 for (
int i = 0; i < mod->numSym; i++ ) {
246 long ll2 = strlen( mod->sym[i].name );
247 if ( 0 != ::strncmp( mod->sym[i].name, name.
c_str(), ( ll1 > ll2 ) ? ll1 : ll2 ) == 0 ) {
265 return ::GetLastError();
268 return static_cast<unsigned long>(
static_cast<unsigned int>( errno ) );
282 LPVOID lpMessageBuffer;
283 ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
284 MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
285 (LPTSTR)&lpMessageBuffer, 0, NULL );
286 errString = (
const char*)lpMessageBuffer;
288 ::LocalFree( lpMessageBuffer );
290 char* cerrString(
nullptr );
292 if ( error == 0xAFFEDEAD ) {
293 cerrString = ::dlerror();
294 if ( !cerrString ) cerrString = ::strerror( error );
296 cerrString = (
char*)
"Unknown error. No information found in strerror()!";
302 cerrString = ::strerror( error );
338 using namespace Gaudi;
370 return (
char**)&( args[0] );
376 # pragma warning( disable : 4996 ) 382 if ( ( env = getenv( var ) ) !=
nullptr ) {
392 if ( ( env = getenv( var ) ) !=
nullptr ) {
403 #if defined( __APPLE__ ) 405 # include "crt_externs.h" 408 #if defined( _WIN32 ) 409 # define environ _environ 410 #elif defined( __APPLE__ ) 411 static char** environ = *_NSGetEnviron();
414 for (
int i = 0; environ[i] !=
nullptr; ++i ) { vars.
push_back( environ[i] ); }
422 # include <execinfo.h> 429 int count = backtrace( addresses, depth );
430 return count > 0 ? count : 0;
432 #else // windows and osx parts not implemented 440 const int totalOffset = offset + 2;
441 const int totalDepth = depth + totalOffset;
447 for (
int i = totalOffset; i < count; ++i ) {
448 void* addr =
nullptr;
469 if ( dladdr( addresses, &info ) && info.dli_fname && info.dli_fname[0] !=
'\0' ) {
470 const char* symbol = info.dli_sname && info.dli_sname[0] !=
'\0' ? info.dli_sname :
nullptr;
472 lib = info.dli_fname;
473 addr = info.dli_saddr;
479 fnc = ( stat == 0 ) ? dmg.
get() : symbol;
488 #else // not implemented for windows and osx 497 return value.
empty() ?
499 ::unsetenv( name.
c_str() ),
502 ::setenv( name.
c_str(), value.
c_str(), overwrite );
505 if ( value.
empty() ) {
507 return ::_putenv( ( name +
"=" ).c_str() );
509 if ( !getenv( name.
c_str() ) || overwrite ) {
511 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.