[PATCH] add a way to get the path to the executable
Submitted by Paolo Bonzini
Link to original bug (#615903)
Description
glib provides no way to retrieve the path to the executable. This is useful in order to implement fully relocatable packages, for example.
The first patch here fixes some imperfections in the documentation.
The second adds a new interface to be used instead (or in addition to) g_set_prgname. This interface receives the whole argv[0] so that it can be used to scan the path. The default prgname becomes the basename of the argv0 value.
GOption is tweaked to call the new interface instead of g_set_prgname.
The Mac OS X part is untested beyond compilation. FreeBSD could also be added (using sysctl).
Automated testing is difficult, I used this program
#include <glib.h>
int main(int argc, char **argv) { g_set_argv0 (argv[0]); printf ("%s\n", g_get_executable_path ()); printf ("%s\n", g_get_prgname ()); }
with various combinations of paths and argv[0] values.
Version: 2.29.x