Files
c3c/lib/std/io/os/chdir.c3
Christoffer Lerno cdabe8fd9e - Create optional with ~ instead of ?. return io::EOF?; becomes return io::EOF~.
- Deprecated use of `?` to create optional.
2026-01-20 16:10:28 +01:00

31 lines
811 B
Plaintext

module std::io::os;
import std::io::path, libc, std::os;
macro void? native_chdir(Path path)
{
@pool()
{
$switch:
$case env::POSIX:
if (posix::chdir(path.str_view().zstr_tcopy()))
{
switch (libc::errno())
{
case errno::EACCES: return io::NO_PERMISSION~;
case errno::ENAMETOOLONG: return io::NAME_TOO_LONG~;
case errno::ENOTDIR: return io::FILE_NOT_DIR~;
case errno::ENOENT: return io::FILE_NOT_FOUND~;
case errno::ELOOP: return io::SYMLINK_FAILED~;
default: return io::GENERAL_ERROR~;
}
}
$case env::WIN32:
// TODO improve with better error handling.
if (win32::setCurrentDirectoryW(path.str_view().to_temp_utf16()!!)) return;
return io::GENERAL_ERROR~;
$default:
return io::UNSUPPORTED_OPERATION~;
$endswitch
};
}