-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_utils.cpp
42 lines (35 loc) · 940 Bytes
/
path_utils.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
#include "path_utils.h"
#include <unistd.h>
String get_executable_path()
{
String result = talloc_string(PATH_MAX);
memset(result.data, 0, sizeof(PATH_MAX));
auto size_wrote = readlink("/proc/self/exe", (char*)result.data, PATH_MAX);
if (size_wrote == -1)
{
fprintf(stderr, "Couldn't get the path to running exe...\n");
exit(1);
}
result.count = size_wrote;
return result;
}
void setcwd(String dir)
{
if (dir)
{
char *c_string_dir = (char*)temp_c_string(dir);
// printf("cd to '%s'\n", c_string_dir);
i32 success = chdir(c_string_dir);
if (success == -1)
{
fprintf(stderr, "Cannot cd to '%s'...\n", c_string_dir);
assert(0);
}
reset_temporary_storage();
}
else
{
fprintf(stderr, "The directory of the executable is NULL. Cannot chdir() there...\n");
assert(0);
}
}