diff options
| author | Emil Williams | 2026-02-20 23:20:14 +0000 |
|---|---|---|
| committer | Emil Williams | 2026-02-20 23:20:14 +0000 |
| commit | 8ad088b4950aba56c3b055c60d2803ce362ce4a2 (patch) | |
| tree | e583a07f17acd68f8b6167d1124b475afe84da27 /chad/experimental/change_directory.c | |
| parent | 5977e472ae122bd8135b7428d9093652d51a2cba (diff) | |
| download | libchad-8e8m.tar.xz libchad-8e8m.tar.zst | |
change directory filename8e8m
Diffstat (limited to 'chad/experimental/change_directory.c')
| -rw-r--r-- | chad/experimental/change_directory.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/chad/experimental/change_directory.c b/chad/experimental/change_directory.c new file mode 100644 index 0000000..988b28a --- /dev/null +++ b/chad/experimental/change_directory.c @@ -0,0 +1,13 @@ +#include <limits.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <chad/experimental/change_directory.h> +int change_directory(char * filename) { + char path[PATH_MAX], * terminator; + if (!realpath(filename, path) + || !(terminator = strrchr(path, '/'))) { return -1; } + *terminator = '\0'; + return chdir(path); +} |
