optimize get_current_dir_name to reduce stack bloat