From d352d3cf415083fd0f07321273d1d03b26a323e0 Mon Sep 17 00:00:00 2001 From: Emil Williams Date: Fri, 20 Feb 2026 05:47:11 +0000 Subject: hopefully more portable --- chad/root.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 chad/root.h (limited to 'chad/root.h') diff --git a/chad/root.h b/chad/root.h new file mode 100644 index 0000000..95a3f8b --- /dev/null +++ b/chad/root.h @@ -0,0 +1,17 @@ +#ifdef CHAD_ROOT_H +#define CHAD_ROOT_H +#include +#include "macros.h" +/* check errno -- chdir */ +always_inline void Root(char * filename) { + extern char * realpath(const char * restrict path, char * restrict resolved_path); + extern int chdir(const char * path); + attribute(noreturn) void abort(void); + char path[PATH_MAX], * terminator; + if (!realpath(filename, path)) { return; } + if ((terminator = strrchr(path, '/'))) { + *terminator = '\0'; + chdir(path); + } +} +#endif /* CHAD_ROOT_H */ -- cgit v1.2.3