Move all files into ports/ subdirectory in preparation for merge with glibc
[glibc.git] / ports / sysdeps / unix / sysv / linux / mips / mips64 / fxstatat64.c
blob1078cc35ac0cc1291e88bfb1480031acb9eb9644
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/>. */
18 #include <errno.h>
19 #include <fcntl.h>
20 #include <stddef.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <sys/stat.h>
24 #include <kernel_stat.h>
26 #include <sysdep.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. */
36 int
37 __fxstatat64 (int vers, int fd, const char *file, struct stat64 *st, int flag)
39 if (__builtin_expect (vers != _STAT_VER_LINUX, 0))
41 __set_errno (EINVAL);
42 return -1;
45 int result;
46 INTERNAL_SYSCALL_DECL (err);
47 struct kernel_stat kst;
49 #ifdef __NR_newfstatat
50 # ifndef __ASSUME_ATFCTS
51 if (__have_atfcts >= 0)
52 # endif
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)
58 __have_atfcts = -1;
59 else
60 # endif
61 if (!__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1))
62 return __xstat64_conv (vers, &kst, st);
63 else
65 __set_errno (INTERNAL_SYSCALL_ERRNO (result, err));
66 return -1;
69 #endif
71 #ifndef __ASSUME_ATFCTS
72 if (flag & ~AT_SYMLINK_NOFOLLOW)
74 __set_errno (EINVAL);
75 return -1;
78 char *buf = NULL;
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
90 numbers. */
91 size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
92 buf = alloca (buflen);
94 __snprintf (buf, buflen, procfd, fd, file);
95 file = buf;
98 if (flag & AT_SYMLINK_NOFOLLOW)
99 result = INTERNAL_SYSCALL (lstat, err, 2, CHECK_STRING (file),
100 __ptrvalue (&kst));
101 else
102 result = INTERNAL_SYSCALL (stat, err, 2, CHECK_STRING (file),
103 __ptrvalue (&kst));
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);
109 return -1;
110 #endif
112 libc_hidden_def (__fxstatat64)