From 3654ce578e6fff53950874adf7e0e4ae0a6eb956 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 3 May 2026 17:29:12 +0900 Subject: refactor: organize directory structure --- src/cc1/sys.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/cc1/sys.c (limited to 'src/cc1/sys.c') diff --git a/src/cc1/sys.c b/src/cc1/sys.c new file mode 100644 index 0000000..693062a --- /dev/null +++ b/src/cc1/sys.c @@ -0,0 +1,21 @@ +#include "sys.h" +#include +#include +#include +#include "../lib/ducc.h" + +static 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); +} -- cgit v1.3.1