summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>2017-09-08 00:41:51 +0200
committerAlbert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>2018-02-01 12:12:32 +0100
commit470885d17c58348b7bcfafc29df406ece3210ea5 (patch)
treedce8f6affd55d11acb6ffdcf680721e8e68aee9c
parent0b055026de0083d3379a4e7bad84e242595bfb79 (diff)
downloadglibc-470885d17c58348b7bcfafc29df406ece3210ea5.tar.gz
Y2038: add function __fstat64_t64 (and __fxstat64_t64)
There is no Y2038-proof linux struct stat for now, so these implementations just use the existing syscalls and convert from kernel 32-bit-time struct stat64 to GLIBC Y2038-ready struct __stat64_t64.
-rw-r--r--include/sys/stat.h2
-rw-r--r--io/Versions5
-rw-r--r--io/fstat64.c7
-rw-r--r--sysdeps/unix/sysv/linux/fxstat64.c50
4 files changed, 64 insertions, 0 deletions
diff --git a/include/sys/stat.h b/include/sys/stat.h
index 7344112674..fe7055f0bb 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -39,6 +39,8 @@ extern int __mkdir (const char *__path, __mode_t __mode);
libc_hidden_proto (__mkdir)
extern int __mknod (const char *__path,
__mode_t __mode, __dev_t __dev);
+extern int __fxstat64_t64 (int __ver, int __fildes,
+ struct __stat64_t64 *__stat_buf);
#if IS_IN (libc) || (IS_IN (rtld) && !defined NO_RTLD_HIDDEN)
hidden_proto (__fxstat)
hidden_proto (__fxstat64)
diff --git a/io/Versions b/io/Versions
index 98898cb9d5..6e781f02ec 100644
--- a/io/Versions
+++ b/io/Versions
@@ -128,4 +128,9 @@ libc {
GLIBC_2.27 {
copy_file_range;
}
+ # Y2038 symbols are given their own version until they can be put in
+ # the right place
+ GLIBC_Y2038 {
+ __fxstat64_t64;
+ }
}
diff --git a/io/fstat64.c b/io/fstat64.c
index 0f4de02cee..60f8a74178 100644
--- a/io/fstat64.c
+++ b/io/fstat64.c
@@ -50,3 +50,10 @@ fstat64 (int fd, struct stat64 *buf)
{
return __fxstat64 (_STAT_VER, fd, buf);
}
+
+int
+attribute_hidden
+__fstat64_t64 (int fd, struct __stat64_t64 *buf)
+{
+ return __fxstat64_t64 (_STAT_VER, fd, buf);
+}
diff --git a/sysdeps/unix/sysv/linux/fxstat64.c b/sysdeps/unix/sysv/linux/fxstat64.c
index 0d053897a0..8a8ca9b8eb 100644
--- a/sysdeps/unix/sysv/linux/fxstat64.c
+++ b/sysdeps/unix/sysv/linux/fxstat64.c
@@ -24,6 +24,8 @@
#include <sysdep.h>
#include <sys/syscall.h>
+#include <xstatconv.h>
+
#include <kernel-features.h>
/* Get information about the file FD in BUF. */
@@ -51,3 +53,51 @@ hidden_ver (___fxstat64, __fxstat64)
strong_alias (___fxstat64, __fxstat64)
hidden_def (__fxstat64)
#endif
+
+/* 64-bit time version */
+
+extern int __y2038_linux_support;
+
+int
+__fxstat64_t64 (int vers, int fd, struct __stat64_t64 *buf)
+{
+ int result;
+ struct stat64 st64;
+
+ if (__y2038_linux_support)
+ {
+ // TODO: use 64-bit syscalls when they become available
+ }
+
+ result = INLINE_SYSCALL (fstat64, 2, fd, &st64);
+#if defined _HAVE_STAT64___ST_INO && !__ASSUME_ST_INO_64_BIT
+ if (__builtin_expect (!result, 1) && st64.__st_ino != (__ino_t) st64.st_ino)
+ st64.st_ino = st64.__st_ino;
+#endif
+ if (!result)
+ {
+ buf->st_dev = st64.st_dev;
+ buf->__pad1 = st64.__pad1;
+
+ buf->__st_ino = st64.__st_ino;
+ buf->st_mode = st64.st_mode;
+ buf->st_nlink = st64.st_nlink;
+ buf->st_uid = st64.st_uid;
+ buf->st_gid = st64.st_gid;
+ buf->st_rdev = st64.st_rdev;
+ buf->__pad2 = st64.__pad2;
+ buf->st_size = st64.st_size;
+ buf->st_blksize = st64.st_blksize;
+
+ buf->st_blocks = st64.st_blocks;
+ buf->st_atim.tv_sec = st64.st_atim.tv_sec;
+ buf->st_atim.tv_nsec = st64.st_atim.tv_nsec;
+ buf->st_mtim.tv_sec = st64.st_mtim.tv_sec;
+ buf->st_mtim.tv_nsec = st64.st_mtim.tv_nsec;
+ buf->st_ctim.tv_sec = st64.st_ctim.tv_sec;
+ buf->st_ctim.tv_nsec = st64.st_ctim.tv_nsec;
+
+ buf->st_ino = st64.st_ino;
+ }
+ return result;
+}