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

I'd also be fine if you wanted to return `Result<(), uint>` for success/errno.