Implement `getcwd`, `chdir`
Closed this issue · 6 comments
Rust's std::env::current_dir
and set_current_dir
are implemented by calls to getcwd
and chdir
. The first half in implementing these is to add support to rsix
: these should go in rsix::process
. There's already a imp/linux_raw
implementation of the getcwd
and chdir
system calls, so this needs a imp/libc
implementation which should just call the libc
function, and then a public API in src/process
. For getcwd
, the public API should take care of allocating the buffer and growing it as needed until getcwd
successfully writes the whole string, returning an OsString
, similar to readlinkat
.
The second step is to implement c-scape
support in terms of the rsix
public API. It may look odd to do it this way, because rsix
will be dynamically allocating, and we'll need to copy the (sub)string out of the dynamic allocated buffer into the fixed-size requested buffer. But one of the goals for c-scape
is to help test rsix
, and to help prepare for rsix
itself to be the low-level API instead of c-scape
.
I'd love to tackle this if someone else isn't already on the job.
Go for it! And please ask questions if anything is unclear.
Oh, I just saw this issue. I was just doing these functions in rsix
(my pr bytecodealliance/rustix#55).
Sorry @cole-miller if you had started 😀; however i'm not planning to do them for mustang
so if you want you can take them to a pr
@cole-miller rsix 0.23.0 is now published, which contains the syscall support for getcwd
and chdir
, so the next step here is to implement them in mustang
. Please feel free to ask questions if anything is unclear!
Sorry for the delay, I've been occupied with something else. I should be able to submit a PR tomorrow!