blob: 6882d83dc4b6bb02791d0d775367bc7d471bee18 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
--- a/utils.cpp
+++ b/utils.cpp
@@ -42,6 +42,7 @@ extern OpenSprinkler os;
static char* get_runtime_path() {
static char path[PATH_MAX];
static unsigned char query = 1;
+ int len;
#ifdef __APPLE__
strcpy(path, "./");
@@ -49,15 +50,12 @@ static char* get_runtime_path() {
#endif
if(query) {
- if(readlink("/proc/self/exe", path, PATH_MAX ) <= 0) {
+ len = readlink("/proc/self/cwd", path, PATH_MAX);
+ if(len <= 0 ) {
return NULL;
}
- char* path_end = strrchr(path, '/');
- if(path_end == NULL) {
- return NULL;
- }
- path_end++;
- *path_end=0;
+ path[len] = '/';
+ path[len+1] = '\0';
query = 0;
}
return path;
|