libstd: refine dynamic memory allocations in os::getcwd() and os::change_dir()

I think that this is the same as below where `.as_slice()` will encompass the entire uninitialized array, it may be better to pass in `.as_ptr()` to clearly say that it's unsafe (because as implemented it's safe in that `CString` doesn't go past the 0