about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/fxstat64.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/sysv/linux/fxstat64.c')
-rw-r--r--sysdeps/unix/sysv/linux/fxstat64.c53
1 files changed, 38 insertions, 15 deletions
diff --git a/sysdeps/unix/sysv/linux/fxstat64.c b/sysdeps/unix/sysv/linux/fxstat64.c
index 9133a0a29b..330af75f11 100644
--- a/sysdeps/unix/sysv/linux/fxstat64.c
+++ b/sysdeps/unix/sysv/linux/fxstat64.c
@@ -16,15 +16,13 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <stddef.h>
-#include <fcntl.h>
+#define __fxstat __redirect___fxstat
 #include <sys/stat.h>
+#undef __fxstat
+#include <fcntl.h>
 #include <kernel_stat.h>
-
 #include <sysdep.h>
-#include <sys/syscall.h>
-
+#include <xstatconv.h>
 #include <statx_cp.h>
 
 /* Get information about the file FD in BUF.  */
@@ -32,17 +30,37 @@
 int
 ___fxstat64 (int vers, int fd, struct stat64 *buf)
 {
-  int result;
-#ifdef __NR_fstat64
-  result = INLINE_SYSCALL (fstat64, 2, fd, buf);
-#else
+#if XSTAT_IS_XSTAT64
+# ifdef __NR_fstat64
+  /* 64-bit kABI outlier, e.g. sparc64.  */
+  if (vers == _STAT_VER_KERNEL)
+    return INLINE_SYSCALL_CALL (fstat, fd, buf);
+  else
+    {
+      struct stat64 st64;
+      int r = INLINE_SYSCALL_CALL (fstat64, fd, &st64);
+      return r ?: __xstat32_conv (vers, &st64, (struct stat *) buf);
+    }
+# elif defined __NR_fstat
+  /* 64-bit kABI, e.g. aarch64, ia64, powerpc64*, s390x, riscv64,
+     and x86_64.  */
+  if (vers == _STAT_VER_KERNEL || vers == _STAT_VER_LINUX)
+    return INLINE_SYSCALL_CALL (fstat, fd, buf);
+  return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
+# else
+  /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32.  */
   struct statx tmp;
-  result = INLINE_SYSCALL (statx, 5, fd, "", AT_EMPTY_PATH, STATX_BASIC_STATS,
-                           &tmp);
-  if (result == 0)
+  int r = INLINE_SYSCALL_CALL (statx, fd, "", AT_EMPTY_PATH,
+			       STATX_BASIC_STATS, &tmp);
+  if (r == 0)
     __cp_stat64_statx (buf, &tmp);
-#endif
-  return result;
+  return r;
+# endif
+#else
+  /* All kABIs with non-LFS support, e.g. arm, csky, i386, hppa, m68k,
+     microblaze, mips32, nios2, sh, powerpc32, and sparc32.  */
+  return INLINE_SYSCALL_CALL (fstat64, fd, buf);
+#endif /* XSTAT_IS_XSTAT64  */
 }
 
 #include <shlib-compat.h>
@@ -56,3 +74,8 @@ hidden_ver (___fxstat64, __fxstat64)
 strong_alias (___fxstat64, __fxstat64)
 hidden_def (__fxstat64)
 #endif
+
+#if XSTAT_IS_XSTAT64
+strong_alias (__fxstat64, __fxstat);
+hidden_ver (__fxstat64, __fxstat)
+#endif