# HG changeset patch # User Tim Ringenbach # Date 1101245072 0 # Node ID 5ce83aad6869a23e34a62667e7c72872fd1758bc # Parent 645eb980404006235c424a8694486dc7eb94d0fd [gaim-migrate @ 11392] This does #2 of binreloc, by reworking ben miller's patch #780565 It's untested, since i don't have a system without /proc, and worse, the m4 macro will compile it to use the hard coded prefix if the /proc file doesn't exist. So this needs to be fixed yet. committer: Tailor Script diff -r 645eb9804040 -r 5ce83aad6869 src/main.c --- a/src/main.c Tue Nov 23 20:25:22 2004 +0000 +++ b/src/main.c Tue Nov 23 21:24:32 2004 +0000 @@ -585,6 +585,55 @@ } #endif /* HAVE_STARTUP_NOTIFICATION */ +static char *gaim_find_binary_location(void *symbol, void *data) +{ + static char *fullname = NULL; + static gboolean first = TRUE; + + char *argv0 = data; + struct stat st; + char *basebuf, *linkbuf, *fullbuf; + + if (!first) + /* We've already been through this. */ + return strdup(fullname); + + first = FALSE; + + if (!argv0) + return NULL; + + + basebuf = g_find_program_in_path(argv0); + + /* But we still need to deal with symbolic links */ + lstat(basebuf, &st); + while ((st.st_mode & S_IFLNK) == S_IFLNK) { + linkbuf = g_malloc(1024); + readlink(basebuf, linkbuf, 1024); + if (linkbuf[0] == G_DIR_SEPARATOR) { + /* an absolute path */ + fullbuf = g_strdup(linkbuf); + } else { + char *dirbuf = g_path_get_dirname(basebuf); + /* a relative path */ + fullbuf = g_strdup_printf("%s%s%s", + dirbuf, G_DIR_SEPARATOR_S, + linkbuf); + g_free(dirbuf); + } + /* There's no memory leak here. Really! */ + g_free(linkbuf); + g_free(basebuf); + basebuf = fullbuf; + lstat(basebuf, &st); + } + + fullname = basebuf; + return strdup(fullname); +} + + /* FUCKING GET ME A TOWEL! */ #ifdef _WIN32 int gaim_main(HINSTANCE hint, int argc, char *argv[]) @@ -623,6 +672,7 @@ #ifdef DEBUG opt_debug = 1; #endif + br_set_locate_fallback_func(gaim_find_binary_location, argv[0]); #ifdef ENABLE_NLS bindtextdomain(PACKAGE, LOCALEDIR); bind_textdomain_codeset(PACKAGE, "UTF-8");