X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=ginge.git;a=blobdiff_plain;f=common%2Fcmn.c;h=7886c7c25d14f3071b05e159041e3dc8c0b6056c;hp=9f802babb8a590efd29e75ce8e7dcd247863b26a;hb=4d0451847a77d420284c7fb0f50b1f167c1118ee;hpb=ed233fce977d411ce024631668f1488d0d078d19 diff --git a/common/cmn.c b/common/cmn.c index 9f802ba..7886c7c 100644 --- a/common/cmn.c +++ b/common/cmn.c @@ -1,3 +1,4 @@ +// vim:shiftwidth=2:expandtab #ifdef LOADER #include "../loader/realfuncs.h" #endif @@ -12,24 +13,24 @@ int make_local_path(char *buf, size_t size, const char *file) ssize_t ret; char *p; - ret = readlink("/proc/self/exe", buf, size - 1); - if (ret < 0) { - perror("readlink"); - goto err; + p = getenv("GINGE_ROOT"); + if (p != NULL) { + strncpy(buf, p, size); + buf[size - 1] = 0; + p = buf + strlen(buf); } - buf[ret] = 0; - - p = strrchr(buf, '/'); - if (p == NULL) - goto err; - p++; + else { + ret = readlink("/proc/self/exe", buf, size - 1); + if (ret < 0) { + perror("readlink"); + goto err; + } + buf[ret] = 0; - if (strstr(p, ".so")) { - p = getenv("GINGE_ROOT"); + p = strrchr(buf, '/'); if (p == NULL) goto err; - strcpy(buf, p); - p = buf + strlen(buf); + p++; } snprintf(p, size - (p - buf), "%s", file);