1 /* Copyright (C) 2005,2006 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>
28 #include <bp-checks.h>
30 #include <kernel-features.h>
32 #include <xstatconv.h>
34 /* Get information about the file NAME in BUF. */
37 __fxstatat64 (int vers
, int fd
, const char *file
, struct stat64
*st
, int flag
)
39 if (__builtin_expect (vers
!= _STAT_VER_LINUX
, 0))
46 INTERNAL_SYSCALL_DECL (err
);
47 struct kernel_stat kst
;
49 #ifdef __NR_newfstatat
50 # ifndef __ASSUME_ATFCTS
51 if (__have_atfcts
>= 0)
54 result
= INTERNAL_SYSCALL (newfstatat
, err
, 4, fd
, file
, &kst
, flag
);
55 # ifndef __ASSUME_ATFCTS
56 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result
, err
), 1)
57 && INTERNAL_SYSCALL_ERRNO (result
, err
) == ENOSYS
)
61 if (!__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result
, err
), 1))
62 return __xstat64_conv (vers
, &kst
, st
);
65 __set_errno (INTERNAL_SYSCALL_ERRNO (result
, err
));
71 #ifndef __ASSUME_ATFCTS
72 if (flag
& ~AT_SYMLINK_NOFOLLOW
)
80 if (fd
!= AT_FDCWD
&& file
[0] != '/')
82 size_t filelen
= strlen (file
);
83 static const char procfd
[] = "/proc/self/fd/%d/%s";
84 /* Buffer for the path name we are going to use. It consists of
85 - the string /proc/self/fd/
86 - the file descriptor number
87 - the file name provided.
88 The final NUL is included in the sizeof. A bit of overhead
89 due to the format elements compensates for possible negative
91 size_t buflen
= sizeof (procfd
) + sizeof (int) * 3 + filelen
;
92 buf
= alloca (buflen
);
94 __snprintf (buf
, buflen
, procfd
, fd
, file
);
98 if (flag
& AT_SYMLINK_NOFOLLOW
)
99 result
= INTERNAL_SYSCALL (lstat
, err
, 2, CHECK_STRING (file
),
102 result
= INTERNAL_SYSCALL (stat
, err
, 2, CHECK_STRING (file
),
105 if (__builtin_expect (!INTERNAL_SYSCALL_ERROR_P (result
, err
), 1))
106 return __xstat64_conv (vers
, &kst
, st
);
108 __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result
, err
), fd
, buf
);
112 libc_hidden_def (__fxstatat64
)