diff --git a/src/tool/SConscript b/src/tool/SConscript index 4fe3a17c4..82b20d96f 100644 --- a/src/tool/SConscript +++ b/src/tool/SConscript @@ -17,7 +17,7 @@ rsvg = envSvg.Program('rsvg-convert','rsvg-convert.c') # build additional test and administrative tools.... artifacts['tools'] = [ env.Program('hello-world','hello.c', install=True) #### hello world (checks C build) - + env.Program('try', 'try.cpp') #### to try out some feature... + + env.Program('try', 'try.cpp', LIBS=support_lib) #### to try out some feature... # + luidgen + rsvg ] diff --git a/src/tool/try.cpp b/src/tool/try.cpp index 16ad0dad2..112aafaaa 100644 --- a/src/tool/try.cpp +++ b/src/tool/try.cpp @@ -15,15 +15,45 @@ // 6/09 - investigating how to build a mixin template providing an operator bool() // 12/9 - tracking down a strange "warning: type qualifiers ignored on function return type" // 1/10 - can we determine at compile time the presence of a certain function (for duck-typing)? +// 1/11 - how to fetch the path of the own executable -- at least under Linux? #include "include/nobugcfg.h" #include +#include + +extern "C" { +#include +} +//#include "lib/error.hpp" +//#include "lib/symbol.hpp" using std::string; using std::cout; +//using lib::Literal; +//using lib::STRING_MAX_RELEVANT; +const size_t STRING_MAX_RELEVANT = 1000; + +//namespace error = lumiera::error; + +//Literal GET_PATH_TO_EXECUTABLE ("/proc/self/exe"); +const char * const GET_PATH_TO_EXECUTABLE ("/proc/self/exe"); + +string +catchMyself () +{ + string buff(STRING_MAX_RELEVANT+1, '\0' ); + ssize_t chars_read = readlink (GET_PATH_TO_EXECUTABLE, &buff[0], STRING_MAX_RELEVANT); + + if (0 > chars_read || chars_read == ssize_t(STRING_MAX_RELEVANT)) +// throw error::Fatal ("unable to discover path of running executable") + throw string("unable to discover path of running executable"); + + buff.resize(chars_read); + return buff; +} int @@ -32,6 +62,7 @@ main (int, char**) //(int argc, char* argv[]) NOBUG_INIT; + cout << "\n\nich bin :" << catchMyself(); cout << "\n.gulp.\n"; return 0;