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

This is generally pretty unsafe in that you want to put the things in the vector before calling `set_len`, but in this case nothing has a destructor so it's ok.