os: Add FileSystem::change_directory
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b7a0ad8ffb
commit
67e9543675
@ -75,11 +75,11 @@ Result<int> luna_main(int argc, char** argv)
|
|||||||
if (args.size() == 1)
|
if (args.size() == 1)
|
||||||
{
|
{
|
||||||
auto home = TRY(os::FileSystem::home_directory());
|
auto home = TRY(os::FileSystem::home_directory());
|
||||||
if (chdir(home.chars()) < 0) perror("cd");
|
TRY(os::FileSystem::change_directory(home.view()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chdir(args[1].chars()) < 0) perror("cd");
|
TRY(os::FileSystem::change_directory(args[1].view()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,5 +17,7 @@ namespace os
|
|||||||
|
|
||||||
Result<String> working_directory();
|
Result<String> working_directory();
|
||||||
Result<String> home_directory();
|
Result<String> home_directory();
|
||||||
|
|
||||||
|
Result<void> change_directory(StringView path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,4 +66,14 @@ namespace os::FileSystem
|
|||||||
|
|
||||||
return String::from_cstring(pw->pw_dir);
|
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 {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user