Re: gnome-devel-list Digest, Vol 4, Issue 1


thanks for the answer, the code mentioned doesn't work for me (in c++), but at least I found how to do this...

util::Utilities::get_executable_path(char *executable_name)
   string                  s, r;           // string, result

  ///copied from

   if (executable_name == 0)
{ return ""; }
   ifstream map_file("/proc/self/maps");

   if (!map_file)
{ return ""; }
   while (getline(map_file, s))
    if (   (s.find(" r-xp ") == string::npos)
        || (s.find('/') == string::npos)
        || (s.find(executable_name) == string::npos))
    { continue; }
    // first compliant line will be supposed to contain executable path
// drop everything before first '/' r = s.substr(s.find('/'), s.size());
    // Get rid of the newline
    if (r.find('\n') != string::npos)
     { r = r.substr(0, r.size() - 1); }
// Get rid of "(deleted)"
    if (r.find(" (deleted)") != string::npos)
    { r = r.substr(0, r.find(" (deleted)")); }

    // Get rid of executable name
    r = r.substr(0, r.rfind('/'));

    return r;

   return "";

greetings, Danny.

gnome-devel-list-request gnome org wrote:

danny van elsen wrote:
hello all,

I'm working on a gnome program in c++, for which I store configuration data in a separate file.

Actually, that *is* the "correct" way. Or should I say: the defacto standard way.

A problem with hardcoding the path in the executable is that it makes your app non-relocatable. Windows app usually find their data files relative to the executable's folder. But you can do the same thing on Linux too. See


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]