- dir = NULL;
- saved_errno = EOPNOTSUPP;
- }
-
- /* If the syscall fails with an expected errno value, resort to
- save_cwd/restore_cwd. */
- if (! dir && EXPECTED_ERRNO (saved_errno))
- {
-# if REPLACE_FCHDIR
- const char *name = _gl_directory_name (fd);
- if (name)
- dir = opendir (name);
- saved_errno = errno;
-# else /* !REPLACE_FCHDIR */
-
- /* Occupy the destination FD slot, so that save_cwd cannot hijack it. */
- struct saved_cwd saved_cwd;
- int fd_reserve = dup (fd);
- if (fd_reserve < 0)
+ DIR *dir = NULL;
+ int saved_errno = EOPNOTSUPP;
+ char buf[OPENAT_BUFFER_SIZE];
+ char *proc_file = openat_proc_name (buf, fd, ".");
+ if (proc_file)