All BSDs seems to be able to allocate memory on getcwd. Use it
Factor out fd_getpath into separate function