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

I'd leave out this `const` and just check the return value of `getcwd_into` in the if condition.