1 /* Copyright (C) 2005-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library. If not, see
16 <http://www.gnu.org/licenses/>. */
24 #include <kernel_stat.h>
27 #include <sys/syscall.h>
29 #include <kernel-features.h>
31 #include <xstatconv.h>
33 /* Get information about the file NAME in BUF. */
36 __fxstatat64 (int vers, int fd, const char *file, struct stat64 *st, int flag)
38 if (__builtin_expect (vers != _STAT_VER_LINUX, 0))
45 INTERNAL_SYSCALL_DECL (err);
46 struct kernel_stat kst;
48 #ifdef __NR_newfstatat
49 # ifndef __ASSUME_ATFCTS
50 if (__have_atfcts >= 0)
53 result = INTERNAL_SYSCALL (newfstatat, err, 4, fd, file, &kst, flag);
54 # ifndef __ASSUME_ATFCTS
55 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1)
56 && INTERNAL_SYSCALL_ERRNO (result, err) == ENOSYS)
60 if (!__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1))
61 return __xstat64_conv (vers, &kst, st);
64 __set_errno (INTERNAL_SYSCALL_ERRNO (result, err));
70 #ifndef __ASSUME_ATFCTS
71 if (flag & ~AT_SYMLINK_NOFOLLOW)
79 if (fd != AT_FDCWD && file[0] != '/')
81 size_t filelen = strlen (file);
82 static const char procfd[] = "/proc/self/fd/%d/%s";
83 /* Buffer for the path name we are going to use. It consists of
84 - the string /proc/self/fd/
85 - the file descriptor number
86 - the file name provided.
87 The final NUL is included in the sizeof. A bit of overhead
88 due to the format elements compensates for possible negative
90 size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
91 buf = alloca (buflen);
93 __snprintf (buf, buflen, procfd, fd, file);
97 if (flag & AT_SYMLINK_NOFOLLOW)
98 result = INTERNAL_SYSCALL (lstat, err, 2, file, &kst);
100 result = INTERNAL_SYSCALL (stat, err, 2, file, &kst);
102 if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result, err), 1))
103 return __xstat64_conv (vers, &kst, st);
105 __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
109 libc_hidden_def (__fxstatat64)