[43/52] libsupport: Add 64 bit time_t support for stat functions

Message ID 20210305201518.798584-44-adhemerval.zanella@linaro.org
State Superseded
Headers
Series Add 64 bit time support on legacy ABIs |

Commit Message

Adhemerval Zanella March 5, 2021, 8:15 p.m. UTC
  The patch adds redirections for xstat, xlstat, and xfstat when
_TIME_BITS=64 is defined.
---
 support/Makefile                |  3 +++
 support/support-xfstat-time64.c | 32 ++++++++++++++++++++++++++++++++
 support/support-xstat-time64.c  | 32 ++++++++++++++++++++++++++++++++
 support/xlstat-time64.c         | 32 ++++++++++++++++++++++++++++++++
 support/xunistd.h               | 13 +++++++++++++
 5 files changed, 112 insertions(+)
 create mode 100644 support/support-xfstat-time64.c
 create mode 100644 support/support-xstat-time64.c
 create mode 100644 support/xlstat-time64.c
  

Comments

Florian Weimer March 5, 2021, 8:42 p.m. UTC | #1
* Adhemerval Zanella via Libc-alpha:

> diff --git a/support/support-xfstat-time64.c b/support/support-xfstat-time64.c
> new file mode 100644
> index 0000000000..324c5d20d2
> --- /dev/null
> +++ b/support/support-xfstat-time64.c
> @@ -0,0 +1,32 @@
> +/* 64-bit time_t stat with error checking.
> +   Copyright (C) 2021 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/>.  */
> +
> +/* NB: Non-standard file name to avoid sysdeps override for xstat.
> */

The comment seems inappropriate.  I think the file name could be
standard: there is no xfstat_time64.c that could be overridden by this.
This applies to the other functions as well.

Rest looks okay.

Thanks,
Florian
  
Adhemerval Zanella March 8, 2021, 1:06 p.m. UTC | #2
On 05/03/2021 17:42, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> diff --git a/support/support-xfstat-time64.c b/support/support-xfstat-time64.c
>> new file mode 100644
>> index 0000000000..324c5d20d2
>> --- /dev/null
>> +++ b/support/support-xfstat-time64.c
>> @@ -0,0 +1,32 @@
>> +/* 64-bit time_t stat with error checking.
>> +   Copyright (C) 2021 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/>.  */
>> +
>> +/* NB: Non-standard file name to avoid sysdeps override for xstat.
>> */
> 
> The comment seems inappropriate.  I think the file name could be
> standard: there is no xfstat_time64.c that could be overridden by this.
> This applies to the other functions as well.

Ack.

> 
> Rest looks okay.
  

Patch

diff --git a/support/Makefile b/support/Makefile
index 846e0dbb26..6f696c70be 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -40,7 +40,9 @@  libsupport-routines = \
   resolv_test \
   set_fortify_handler \
   support-xfstat \
+  support-xfstat-time64 \
   support-xstat \
+  support-xstat-time64 \
   support_become_root \
   support_can_chroot \
   support_capture_subprocess \
@@ -111,6 +113,7 @@  libsupport-routines = \
   xlisten \
   xlseek \
   xlstat \
+  xlstat-time64 \
   xmalloc \
   xmemstream \
   xmkdir \
diff --git a/support/support-xfstat-time64.c b/support/support-xfstat-time64.c
new file mode 100644
index 0000000000..324c5d20d2
--- /dev/null
+++ b/support/support-xfstat-time64.c
@@ -0,0 +1,32 @@ 
+/* 64-bit time_t stat with error checking.
+   Copyright (C) 2021 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/>.  */
+
+/* NB: Non-standard file name to avoid sysdeps override for xstat.  */
+
+#include <support/check.h>
+#include <support/xunistd.h>
+#include <sys/stat.h>
+
+#if __TIMESIZE != 64
+void
+xfstat_time64 (int fd, struct __stat64_t64 *result)
+{
+  if (__fstat64_time64 (fd, result) != 0)
+    FAIL_EXIT1 ("__fstat64_time64 (%d): %m", fd);
+}
+#endif
diff --git a/support/support-xstat-time64.c b/support/support-xstat-time64.c
new file mode 100644
index 0000000000..7d0194b98a
--- /dev/null
+++ b/support/support-xstat-time64.c
@@ -0,0 +1,32 @@ 
+/* 64-bit time_t stat with error checking.
+   Copyright (C) 2021 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/>.  */
+
+/* NB: Non-standard file name to avoid sysdeps override for xstat.  */
+
+#include <support/check.h>
+#include <support/xunistd.h>
+#include <sys/stat.h>
+
+#if __TIMESIZE != 64
+void
+xstat_time64 (const char *path, struct __stat64_t64 *result)
+{
+  if (__stat64_time64 (path, result) != 0)
+    FAIL_EXIT1 ("__stat64_time64 (\"%s\"): %m", path);
+}
+#endif
diff --git a/support/xlstat-time64.c b/support/xlstat-time64.c
new file mode 100644
index 0000000000..ef4d922635
--- /dev/null
+++ b/support/xlstat-time64.c
@@ -0,0 +1,32 @@ 
+/* 64-bit time_t stat with error checking.
+   Copyright (C) 2021 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/>.  */
+
+/* NB: Non-standard file name to avoid sysdeps override for xstat.  */
+
+#include <support/check.h>
+#include <support/xunistd.h>
+#include <sys/stat.h>
+
+#if __TIMESIZE != 64
+void
+xlstat_time64 (const char *path, struct __stat64_t64 *result)
+{
+  if (__lstat64_time64 (path, result) != 0)
+    FAIL_EXIT1 ("__lstat64_time64 (\"%s\"): %m", path);
+}
+#endif
diff --git a/support/xunistd.h b/support/xunistd.h
index c642588c29..e4ade65c85 100644
--- a/support/xunistd.h
+++ b/support/xunistd.h
@@ -24,6 +24,7 @@ 
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <unistd.h>
 
 __BEGIN_DECLS
@@ -35,9 +36,21 @@  pid_t xwaitpid (pid_t, int *status, int flags);
 void xpipe (int[2]);
 void xdup2 (int, int);
 int xopen (const char *path, int flags, mode_t);
+#ifndef __USE_TIME_BITS64
+# ifdef __USE_FILE_OFFSET64
+void xstat (const char *path, struct stat *);
+void xlstat (const char *path, struct stat *);
+void xfstat (int fd, struct stat *);
+# else
 void xstat (const char *path, struct stat64 *);
 void xlstat (const char *path, struct stat64 *);
 void xfstat (int fd, struct stat64 *);
+# endif
+#else
+void __REDIRECT (xstat, (const char *path, struct stat *), xstat_time64);
+void __REDIRECT (xlstat, (const char *path, struct stat *), xlstat_time64);
+void __REDIRECT (xfstat, (int fd, struct stat *), xfstat_time64);
+#endif
 void xmkdir (const char *path, mode_t);
 void xchroot (const char *path);
 void xunlink (const char *path);