aboutsummaryrefslogtreecommitdiff
path: root/chad/root.h
diff options
context:
space:
mode:
Diffstat (limited to 'chad/root.h')
-rw-r--r--chad/root.h17
1 files changed, 17 insertions, 0 deletions
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 <limits.h>
+#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 */