os: Add FileSystem::change_directory
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-04-18 18:46:19 +02:00
parent b7a0ad8ffb
commit 67e9543675
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 14 additions and 2 deletions

View File

@ -75,11 +75,11 @@ Result<int> luna_main(int argc, char** argv)
if (args.size() == 1)
{
auto home = TRY(os::FileSystem::home_directory());
if (chdir(home.chars()) < 0) perror("cd");
TRY(os::FileSystem::change_directory(home.view()));
continue;
}
if (chdir(args[1].chars()) < 0) perror("cd");
TRY(os::FileSystem::change_directory(args[1].view()));
continue;
}

View File

@ -17,5 +17,7 @@ namespace os
Result<String> working_directory();
Result<String> home_directory();
Result<void> change_directory(StringView path);
}
}

View File

@ -66,4 +66,14 @@ namespace os::FileSystem
return String::from_cstring(pw->pw_dir);
}
Result<void> change_directory(StringView path)
{
long rc = syscall(SYS_chdir, path.chars());
int _ignore = TRY(Result<int>::from_syscall(rc));
ignore(_ignore);
return {};
}
}