-int
-fstatat (int fd, char const *file, struct stat *st, int flag)
-{
- struct saved_cwd saved_cwd;
- int saved_errno;
- int err;
-
- if (fd == AT_FDCWD || IS_ABSOLUTE_FILE_NAME (file))
- return (flag == AT_SYMLINK_NOFOLLOW
- ? lstat (file, st)
- : stat (file, st));
-
- {
- char *proc_file;
- BUILD_PROC_NAME (proc_file, fd, file);
- err = (flag == AT_SYMLINK_NOFOLLOW
- ? lstat (proc_file, st)
- : stat (proc_file, st));
- /* If the syscall succeeds, or if it fails with an unexpected
- errno value, then return right away. Otherwise, fall through
- and resort to using save_cwd/restore_cwd. */
- if (0 <= err || ! EXPECTED_ERRNO (errno))
- return err;
- }
-
- if (save_cwd (&saved_cwd) != 0)
- openat_save_fail (errno);
-
- err = fchdir (fd);
- saved_errno = errno;
-
- if (! err)
- {
- err = (flag == AT_SYMLINK_NOFOLLOW
- ? lstat (file, st)
- : stat (file, st));
- saved_errno = errno;