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 ) 242 *pFunction = FuncPtrCast<EntryPoint>(::dlsym( handle, name.
c_str() ) );
250 #elif defined( __APPLE__ ) 252 if ( !( *pFunction ) ) {
257 if ( 0 == *pFunction ) {
265 HMODULE* mod = (HMODULE*)handle;
268 for (
int i = 0; i < mod->numSym; i++ ) {
269 long ll2 = strlen( mod->sym[i].name );
270 if ( 0 != ::strncmp( mod->sym[i].name, name.
c_str(), ( ll1 > ll2 ) ? ll1 : ll2 ) == 0 ) {
290 return ::GetLastError();
293 return static_cast<unsigned long>(
static_cast<unsigned int>( errno ) );
309 LPVOID lpMessageBuffer;
310 ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
311 MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
312 (LPTSTR)&lpMessageBuffer, 0, NULL );
313 errString = (
const char*)lpMessageBuffer;
315 ::LocalFree( lpMessageBuffer );
317 char* cerrString(
nullptr );
319 if ( error == 0xAFFEDEAD ) {
320 cerrString = (
char*)::dlerror();
321 if ( !cerrString ) cerrString = ::strerror( error );
323 cerrString = (
char*)
"Unknown error. No information found in strerror()!";
329 cerrString = ::strerror( error );
370 using namespace Gaudi;
405 return (
char**)&( args[0] );
411 #pragma warning( disable : 4996 ) 418 if ( ( env = getenv( var ) ) !=
nullptr ) {
429 if ( ( env = getenv( var ) ) !=
nullptr ) {
440 #if defined( __APPLE__ ) 442 #include "crt_externs.h" 446 #if defined( _WIN32 ) 447 #define environ _environ 448 #elif defined( __APPLE__ ) 449 static char** environ = *_NSGetEnviron();
452 for (
int i = 0; environ[i] !=
nullptr; ++i ) {
462 #include <execinfo.h> 470 int count = backtrace( addresses, depth );
471 return count > 0 ? count : 0;
473 #else // windows and osx parts not implemented 482 const int totalOffset = offset + 2;
483 const int totalDepth = depth + totalOffset;
489 for (
int i = totalOffset; i < count; ++i ) {
490 void* addr =
nullptr;
513 if ( dladdr( addresses, &info ) && info.dli_fname && info.dli_fname[0] !=
'\0' ) {
514 const char* symbol = info.dli_sname && info.dli_sname[0] !=
'\0' ? info.dli_sname :
nullptr;
516 lib = info.dli_fname;
517 addr = info.dli_saddr;
523 fnc = ( stat == 0 ) ? dmg.
get() : symbol;
532 #else // not implemented for windows and osx 542 return value.
empty() ?
544 ::unsetenv( name.
c_str() ),
547 ::setenv( name.
c_str(), value.
c_str(), overwrite );
550 if ( value.
empty() ) {
552 return ::_putenv( ( name +
"=" ).c_str() );
554 if ( !getenv( name.
c_str() ) || overwrite ) {
556 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.