avoid excessive stack usage in getcwd