| 1 | #ifdef LOADER |
| 2 | #include "../loader/realfuncs.h" |
| 3 | #endif |
| 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | #include <unistd.h> |
| 7 | |
| 8 | #include "cmn.h" |
| 9 | |
| 10 | int make_local_path(char *buf, size_t size, const char *file) |
| 11 | { |
| 12 | ssize_t ret; |
| 13 | char *p; |
| 14 | |
| 15 | ret = readlink("/proc/self/exe", buf, size - 1); |
| 16 | if (ret < 0) { |
| 17 | perror("readlink"); |
| 18 | goto err; |
| 19 | } |
| 20 | buf[ret] = 0; |
| 21 | |
| 22 | p = strrchr(buf, '/'); |
| 23 | if (p == NULL) |
| 24 | goto err; |
| 25 | p++; |
| 26 | |
| 27 | if (strstr(p, ".so")) { |
| 28 | p = getenv("GINGE_ROOT"); |
| 29 | if (p == NULL) |
| 30 | goto err; |
| 31 | strcpy(buf, p); |
| 32 | p = buf + strlen(buf); |
| 33 | } |
| 34 | |
| 35 | snprintf(p, size - (p - buf), "%s", file); |
| 36 | |
| 37 | return 0; |
| 38 | |
| 39 | err: |
| 40 | fprintf(stderr, "ginge: can't determine root, buf: \"%s\"\n", buf); |
| 41 | return -1; |
| 42 | } |
| 43 | |