diff options
| -rw-r--r-- | main.c | 1 | ||||
| -rw-r--r-- | preprocess.c | 9 | ||||
| -rw-r--r-- | std.h | 6 | ||||
| -rw-r--r-- | sys.c | 15 |
4 files changed, 30 insertions, 1 deletions
@@ -3,6 +3,7 @@ #include "std.h" #include "common.c" #include "io.c" +#include "sys.c" #include "preprocess.c" #include "tokenize.c" #include "ast.c" diff --git a/preprocess.c b/preprocess.c index 8607fdf..6547028 100644 --- a/preprocess.c +++ b/preprocess.c @@ -796,9 +796,16 @@ void pp_dump(PpToken* t, int include_whitespace) { } } +char* get_ducc_include_path() { + const char* self_dir = get_self_dir(); + char* buf = calloc(strlen(self_dir) + strlen("/include") + 1, sizeof(char)); + sprintf(buf, "%s/include", self_dir); + return buf; +} + PpToken* do_preprocess(InFile* src, int depth, PpMacros* pp_macros) { Preprocessor* pp = preprocessor_new(src, depth, pp_macros); - add_include_path(pp, "/home/ken/src/ducc/include"); + add_include_path(pp, get_ducc_include_path()); add_include_path(pp, "/usr/include"); pp_tokenize_all(pp); process_pp_directives(pp); @@ -38,3 +38,9 @@ int vfprintf(FILE*, const char*, va_list); #define F_OK 0 #define R_OK 4 int access(const char*, int); + +#define PATH_MAX 4096 + +typedef long ssize_t; +ssize_t readlink(const char*, char*, size_t); +char* dirname(char*); @@ -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); +} |
