]>
Commit | Line | Data |
---|---|---|
d4697bc9 | 1 | /* Copyright (C) 2005-2014 Free Software Foundation, Inc. |
26cec518 UD |
2 | This file is part of the GNU C Library. |
3 | ||
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. | |
8 | ||
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. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
26cec518 UD |
17 | |
18 | /* Ho hum, if fxstatat == fxstatat64 we must get rid of the prototype or gcc | |
19 | will complain since they don't strictly match. */ | |
20 | #define __fxstatat64 __fxstatat64_disable | |
21 | ||
22 | #include <errno.h> | |
23 | #include <fcntl.h> | |
24 | #include <stddef.h> | |
25 | #include <stdio.h> | |
478f33c9 | 26 | #include <string.h> |
26cec518 UD |
27 | #include <sys/stat.h> |
28 | #include <kernel_stat.h> | |
29 | ||
30 | #include <sysdep.h> | |
31 | #include <sys/syscall.h> | |
26cec518 | 32 | |
6ddd37a4 | 33 | #include <kernel-features.h> |
26cec518 UD |
34 | |
35 | #include <xstatconv.h> | |
36 | ||
26cec518 UD |
37 | |
38 | /* Get information about the file NAME relative to FD in ST. */ | |
39 | int | |
40 | __fxstatat (int vers, int fd, const char *file, struct stat *st, int flag) | |
41 | { | |
d369ad76 UD |
42 | int result; |
43 | INTERNAL_SYSCALL_DECL (err); | |
44 | struct stat64 st64; | |
45 | ||
46 | #ifdef __NR_fstatat64 | |
47 | # ifndef __ASSUME_ATFCTS | |
48 | if (__have_atfcts >= 0) | |
49 | # endif | |
50 | { | |
51 | result = INTERNAL_SYSCALL (fstatat64, err, 4, fd, file, &st64, flag); | |
52 | # ifndef __ASSUME_ATFCTS | |
53 | if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1) | |
54 | && INTERNAL_SYSCALL_ERRNO (result, err) == ENOSYS) | |
55 | __have_atfcts = -1; | |
56 | else | |
57 | # endif | |
58 | if (!__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1)) | |
59 | return __xstat32_conv (vers, &st64, st); | |
60 | else | |
61 | { | |
62 | __set_errno (INTERNAL_SYSCALL_ERRNO (result, err)); | |
63 | return -1; | |
64 | } | |
65 | } | |
66 | #endif | |
67 | ||
68 | #ifndef __ASSUME_ATFCTS | |
a1ffb40e | 69 | if (__glibc_unlikely (flag & ~AT_SYMLINK_NOFOLLOW)) |
26cec518 UD |
70 | { |
71 | __set_errno (EINVAL); | |
72 | return -1; | |
73 | } | |
74 | ||
75 | char *buf = NULL; | |
76 | ||
77 | if (fd != AT_FDCWD && file[0] != '/') | |
78 | { | |
79 | size_t filelen = strlen (file); | |
a1ffb40e | 80 | if (__glibc_unlikely (filelen == 0)) |
801720e6 UD |
81 | { |
82 | __set_errno (ENOENT); | |
83 | return -1; | |
84 | } | |
85 | ||
26cec518 UD |
86 | static const char procfd[] = "/proc/self/fd/%d/%s"; |
87 | /* Buffer for the path name we are going to use. It consists of | |
88 | - the string /proc/self/fd/ | |
89 | - the file descriptor number | |
90 | - the file name provided. | |
91 | The final NUL is included in the sizeof. A bit of overhead | |
92 | due to the format elements compensates for possible negative | |
93 | numbers. */ | |
94 | size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen; | |
95 | buf = alloca (buflen); | |
96 | ||
97 | __snprintf (buf, buflen, procfd, fd, file); | |
98 | file = buf; | |
99 | } | |
100 | ||
26cec518 UD |
101 | if (vers == _STAT_VER_KERNEL) |
102 | { | |
103 | if (flag & AT_SYMLINK_NOFOLLOW) | |
6277fdab | 104 | result = INTERNAL_SYSCALL (lstat, err, 2, file, |
f3aae3f3 | 105 | (struct kernel_stat *) st); |
26cec518 | 106 | else |
6277fdab | 107 | result = INTERNAL_SYSCALL (stat, err, 2, file, |
f3aae3f3 | 108 | (struct kernel_stat *) st); |
26cec518 UD |
109 | goto out; |
110 | } | |
111 | ||
26cec518 | 112 | if (flag & AT_SYMLINK_NOFOLLOW) |
70d9946a | 113 | result = INTERNAL_SYSCALL (lstat64, err, 2, file, &st64); |
26cec518 | 114 | else |
70d9946a | 115 | result = INTERNAL_SYSCALL (stat64, err, 2, file, &st64); |
a1ffb40e | 116 | if (__glibc_likely (!INTERNAL_SYSCALL_ERROR_P (result, err))) |
26cec518 | 117 | return __xstat32_conv (vers, &st64, st); |
26cec518 UD |
118 | |
119 | out: | |
a1ffb40e | 120 | if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (result, err))) |
baf532c1 UD |
121 | { |
122 | __atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf); | |
123 | result = -1; | |
124 | } | |
26cec518 UD |
125 | |
126 | return result; | |
d369ad76 | 127 | #endif |
26cec518 | 128 | } |
d369ad76 | 129 | libc_hidden_def (__fxstatat) |
26cec518 UD |
130 | #ifdef XSTAT_IS_XSTAT64 |
131 | # undef __fxstatat64 | |
132 | strong_alias (__fxstatat, __fxstatat64); | |
c99445f8 | 133 | libc_hidden_ver (__fxstatat, __fxstatat64) |
26cec518 | 134 | #endif |