aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sys.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys.c')
-rw-r--r--src/sys.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/sys.c b/src/sys.c
new file mode 100644
index 0000000..aa7b13d
--- /dev/null
+++ b/src/sys.c
@@ -0,0 +1,15 @@
+char* get_self_path() {
+ char* buf = calloc(PATH_MAX, sizeof(char));
+ ssize_t len = readlink("/proc/self/exe", buf, PATH_MAX - 1);
+ if (len == -1 || len == PATH_MAX - 1) {
+ return NULL;
+ }
+ buf[len] = '\0';
+ return buf;
+}
+
+// It returns a path not including final / except for root directory.
+char* get_self_dir() {
+ char* path = get_self_path();
+ return dirname(path);
+}