From f02cb19cca562869dd9a0698a3468b708c3ca690 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 22 Feb 2013 16:51:10 -0500 Subject: [PATCH] Set XDG_DATA_PATH if appropriate, etc. --- macelf/macelf.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/macelf/macelf.c b/macelf/macelf.c index bb20963..a15b678 100644 --- a/macelf/macelf.c +++ b/macelf/macelf.c @@ -306,7 +306,7 @@ static void *mojoelf_resolver_internal(void *handle, const char *sym) addr = MOJOELF_dlsym(lib->handle, sym); } // if - else // uh oh, we couldn't satify this dependency! + else // uh oh, we couldn't satisfy this dependency! { // don't ever supply this; it's a weak symbol used by gprof and should resolve to NULL. if (strcmp(sym, "__gmon_start__") == 0) @@ -625,6 +625,24 @@ static void setup_native_overrides(const char *_list) } // setup_native_overrides +static void set_xdg_path() +{ + if (getenv("XDG_DATA_PATH") != NULL) + return; // already set, don't override it. + + const char *home = getenv("HOME"); + if (!home) + return; // oh well. + + const char *append = "/Library/Application Support/MojoELF"; + const size_t len = strlen(home) + strlen(append) + 1; + char *path = (char *) alloca(len); + snprintf(path, len, "%s%s", home, append); + mkdir(path, 0600); + setenv("XDG_DATA_PATH", path, 1); +} // set_xdg_path + + // looks a lot like main(), huh? :) typedef void(*EntryFn)(int,char**,char**); @@ -634,8 +652,6 @@ int main(int argc, char **argv, char **envp) int startarg = 1; int i; - ld_library_path = getenv("LD_LIBRARY_PATH"); - for (i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -721,6 +737,11 @@ int main(int argc, char **argv, char **envp) elf = argv[startarg]; program_invocation_name = elf; + if (!ld_library_path) // try this if nothing else was specified. + ld_library_path = getenv("LD_LIBRARY_PATH"); + + set_xdg_path(); // set here, in case a static constructor needs this. + // !!! FIXME: use our mmap() code instead. void *lib = MOJOELF_dlopen_file(argv[startarg], &mojoelf_callbacks); if (lib == NULL)