comparison console/gntgaim.c @ 15036:78cab68de463

[gaim-migrate @ 17818] Add fallback binary relocation support (copied from gtk gaim). This might make Alver's IRIX build work. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Sat, 25 Nov 2006 16:47:23 +0000
parents d478f3853671
children 1c4d0d3f4f5f
comparison
equal deleted inserted replaced
15035:8c5c4d7d53a5 15036:78cab68de463
25 #include "debug.h" 25 #include "debug.h"
26 #include "eventloop.h" 26 #include "eventloop.h"
27 #include "ft.h" 27 #include "ft.h"
28 #include "log.h" 28 #include "log.h"
29 #include "notify.h" 29 #include "notify.h"
30 #include "prefix.h"
30 #include "prefs.h" 31 #include "prefs.h"
31 #include "prpl.h" 32 #include "prpl.h"
32 #include "pounce.h" 33 #include "pounce.h"
33 #include "savedstatuses.h" 34 #include "savedstatuses.h"
34 #include "sound.h" 35 #include "sound.h"
153 static GaimEventLoopUiOps * 154 static GaimEventLoopUiOps *
154 gnt_eventloop_get_ui_ops(void) 155 gnt_eventloop_get_ui_ops(void)
155 { 156 {
156 return &eventloop_ops; 157 return &eventloop_ops;
157 } 158 }
159
160 /* This is copied from gtkgaim */
161 static char *
162 gnt_find_binary_location(void *symbol, void *data)
163 {
164 static char *fullname = NULL;
165 static gboolean first = TRUE;
166
167 char *argv0 = data;
168 struct stat st;
169 char *basebuf, *linkbuf, *fullbuf;
170
171 if (!first)
172 /* We've already been through this. */
173 return strdup(fullname);
174
175 first = FALSE;
176
177 if (!argv0)
178 return NULL;
179
180
181 basebuf = g_find_program_in_path(argv0);
182
183 /* But we still need to deal with symbolic links */
184 g_lstat(basebuf, &st);
185 while ((st.st_mode & S_IFLNK) == S_IFLNK) {
186 int written;
187 linkbuf = g_malloc(1024);
188 written = readlink(basebuf, linkbuf, 1024 - 1);
189 if (written == -1)
190 {
191 /* This really shouldn't happen, but do we
192 * need something better here? */
193 g_free(linkbuf);
194 continue;
195 }
196 linkbuf[written] = '\0';
197 if (linkbuf[0] == G_DIR_SEPARATOR) {
198 /* an absolute path */
199 fullbuf = g_strdup(linkbuf);
200 } else {
201 char *dirbuf = g_path_get_dirname(basebuf);
202 /* a relative path */
203 fullbuf = g_strdup_printf("%s%s%s",
204 dirbuf, G_DIR_SEPARATOR_S,
205 linkbuf);
206 g_free(dirbuf);
207 }
208 /* There's no memory leak here. Really! */
209 g_free(linkbuf);
210 g_free(basebuf);
211 basebuf = fullbuf;
212 g_lstat(basebuf, &st);
213 }
214
215 fullname = basebuf;
216 return strdup(fullname);
217 }
218
158 219
159 /* This is mostly copied from gtkgaim's source tree */ 220 /* This is mostly copied from gtkgaim's source tree */
160 static void 221 static void
161 show_usage(const char *name, gboolean terse) 222 show_usage(const char *name, gboolean terse)
162 { 223 {
197 {"nologin", no_argument, NULL, 'n'}, 258 {"nologin", no_argument, NULL, 'n'},
198 {"session", required_argument, NULL, 's'}, 259 {"session", required_argument, NULL, 's'},
199 {"version", no_argument, NULL, 'v'}, 260 {"version", no_argument, NULL, 'v'},
200 {0, 0, 0, 0} 261 {0, 0, 0, 0}
201 }; 262 };
263
264 gaim_br_set_locate_fallback_func(gnt_find_binary_location, argv[0]);
202 265
203 /* scan command-line options */ 266 /* scan command-line options */
204 opterr = 1; 267 opterr = 1;
205 while ((opt = getopt_long(argc, argv, 268 while ((opt = getopt_long(argc, argv,
206 #ifndef _WIN32 269 #ifndef _WIN32