#include #include #include #include #include #include #include #include #include namespace os::FileSystem { bool exists(StringView path) { struct stat st; if (stat(path.chars(), &st) < 0) return false; return true; } bool is_directory(StringView path) { struct stat st; if (stat(path.chars(), &st) < 0) return false; return S_ISDIR(st.st_mode); } Result create_directory(StringView path, mode_t mode) { long rc = syscall(SYS_mkdir, path.chars(), mode); int _ignore = TRY(Result::from_syscall(rc)); ignore(_ignore); return {}; } Result remove(StringView path) { long rc = syscall(SYS_unlink, path.chars(), 0); int _ignore = TRY(Result::from_syscall(rc)); ignore(_ignore); return {}; } Result working_directory() { char* ptr = getcwd(NULL, 0); if (!ptr) return err(errno); return String { ptr }; } Result home_directory() { char* home = getenv("HOME"); if (home) return String::from_cstring(home); struct passwd* pw = getpwuid(getuid()); if (!pw) return err(ENOENT); return String::from_cstring(pw->pw_dir); } Result change_directory(StringView path) { long rc = syscall(SYS_chdir, path.chars()); int _ignore = TRY(Result::from_syscall(rc)); ignore(_ignore); return {}; } }