getcwd implementation for bsd, osx