new file mode 100644
@@ -0,0 +1,64 @@
+/* Get file status. LoongArch version.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#define __fstat __redirect___fstat
+#define fstat __redirect_fstat
+#include <sys/stat.h>
+#undef __fstat
+#undef fstat
+
+#include "fstatat64_time64_statx.h"
+
+#if __LINUX_KERNEL_VERSION >= 0x060a06
+static int __fstat_syscall_supported = 1;
+#endif
+
+int
+__fstat64 (int fd, struct __stat64_t64 *buf)
+{
+ int r;
+#if __LINUX_KERNEL_VERSION >= 0x060a06
+ int supported = atomic_load_relaxed (&__fstat_syscall_supported);
+ if (supported)
+ {
+ r = INTERNAL_SYSCALL_CALL (fstat, fd, buf);
+ if (r == 0)
+ return r;
+ else if (r != -ENOSYS)
+ return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r);
+
+ atomic_store_relaxed (&__fstat_syscall_supported, 0);
+ }
+#endif
+
+ if (fd < 0)
+ {
+ __set_errno (EBADF);
+ return -1;
+ }
+
+ r = fstatat64_time64_statx (fd, "", buf, AT_EMPTY_PATH);
+ return INTERNAL_SYSCALL_ERROR_P (r)
+ ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r)
+ : 0;
+}
+
+hidden_def (__fstat64)
+weak_alias (__fstat64, fstat64)
+strong_alias (__fstat64, __fstat)
+weak_alias (__fstat64, fstat)
new file mode 100644
@@ -0,0 +1,59 @@
+/* Get file status. LoongArch version.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#define __fstatat __redirect___fstatat
+#define fstatat __redirect_fstatat
+#include <sys/stat.h>
+#undef __fstatat
+#undef fstatat
+
+#include "fstatat64_time64_statx.h"
+
+#if __LINUX_KERNEL_VERSION >= 0x060a06
+static int __newfstatat_syscall_supported = 1;
+#endif
+
+int
+__fstatat64 (int fd, const char *file, struct __stat64_t64 *buf,
+ int flag)
+{
+ int r;
+#if __LINUX_KERNEL_VERSION >= 0x060a06
+ int supported = atomic_load_relaxed (&__newfstatat_syscall_supported);
+ if (supported)
+ {
+ r = INTERNAL_SYSCALL_CALL (newfstatat, fd, file, buf, flag);
+ if (r == 0)
+ return r;
+ else if (r != -ENOSYS)
+ return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r);
+ atomic_store_relaxed (&__newfstatat_syscall_supported, 0);
+ }
+#endif
+
+ r = fstatat64_time64_statx (fd, file, buf, flag);
+ return INTERNAL_SYSCALL_ERROR_P (r)
+ ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r)
+ : 0;
+}
+
+hidden_def (__fstatat64)
+weak_alias (__fstatat64, fstatat64)
+strong_alias (__fstatat64, __fstatat)
+weak_alias (__fstatat64, fstatat)
+strong_alias (__fstatat64, __GI___fstatat);
new file mode 100644
@@ -0,0 +1,54 @@
+/* Get file status. LoongArch version.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <fcntl.h>
+#include <sys/sysmacros.h>
+#include <internal-stat.h>
+
+static inline int
+fstatat64_time64_statx (int fd, const char *file, struct __stat64_t64 *buf,
+ int flag)
+{
+ struct statx tmp;
+ int r = INTERNAL_SYSCALL_CALL (statx, fd, file, AT_NO_AUTOMOUNT | flag,
+ STATX_BASIC_STATS, &tmp);
+ if (r != 0)
+ return r;
+
+ *buf = (struct __stat64_t64)
+ {
+ .st_dev = __gnu_dev_makedev (tmp.stx_dev_major, tmp.stx_dev_minor),
+ .st_rdev = __gnu_dev_makedev (tmp.stx_rdev_major, tmp.stx_rdev_minor),
+ .st_ino = tmp.stx_ino,
+ .st_mode = tmp.stx_mode,
+ .st_nlink = tmp.stx_nlink,
+ .st_uid = tmp.stx_uid,
+ .st_gid = tmp.stx_gid,
+ .st_atime = tmp.stx_atime.tv_sec,
+ .st_atim.tv_nsec = tmp.stx_atime.tv_nsec,
+ .st_mtime = tmp.stx_mtime.tv_sec,
+ .st_mtim.tv_nsec = tmp.stx_mtime.tv_nsec,
+ .st_ctime = tmp.stx_ctime.tv_sec,
+ .st_ctim.tv_nsec = tmp.stx_ctime.tv_nsec,
+ .st_size = tmp.stx_size,
+ .st_blocks = tmp.stx_blocks,
+ .st_blksize = tmp.stx_blksize,
+ };
+
+ return r;
+}