changeset 10252:5ce83aad6869

[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 <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Tue, 23 Nov 2004 21:24:32 +0000
parents 645eb9804040
children 949b7986f42c
files src/main.c
diffstat 1 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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");