diff options
author | Florian Weimer <fweimer@redhat.com> | 2024-08-16 16:05:20 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2024-08-16 16:05:20 +0200 |
commit | e7c14e542d8d858b824b5df4f4e3dc93695e6171 (patch) | |
tree | dc05ca2e7522b2dacf47eadd59c06580690e53f5 /support | |
parent | bf2927484152e12996af60ea439cf94b66fcd81d (diff) | |
download | glibc-e7c14e542d8d858b824b5df4f4e3dc93695e6171.zip glibc-e7c14e542d8d858b824b5df4f4e3dc93695e6171.tar.gz glibc-e7c14e542d8d858b824b5df4f4e3dc93695e6171.tar.bz2 |
support: Use macros for *stat wrappers
Macros will automatically use the correct types, without
having to fiddle with internal glibc macros. It's also
impossible to get the types wrong due to aliasing because
support_check_stat_fd and support_check_stat_path do not
depend on the struct stat* types.
The changes reveal some inconsistencies in tests.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'support')
-rw-r--r-- | support/Makefile | 8 | ||||
-rw-r--r-- | support/support-xfstat-time64.c | 32 | ||||
-rw-r--r-- | support/support-xstat-time64.c | 32 | ||||
-rw-r--r-- | support/support-xstat.c | 30 | ||||
-rw-r--r-- | support/support_check_stat_fd.c (renamed from support/xlstat.c) | 11 | ||||
-rw-r--r-- | support/support_check_stat_path.c (renamed from support/support-xfstat.c) | 9 | ||||
-rw-r--r-- | support/xlstat-time64.c | 32 | ||||
-rw-r--r-- | support/xunistd.h | 30 |
8 files changed, 25 insertions, 159 deletions
diff --git a/support/Makefile b/support/Makefile index 5b1c96a..6e3c553 100644 --- a/support/Makefile +++ b/support/Makefile @@ -42,14 +42,12 @@ libsupport-routines = \ resolv_test \ set_fortify_handler \ support-open-dev-null-range \ - support-xfstat \ - support-xfstat-time64 \ - support-xstat \ - support-xstat-time64 \ support_become_root \ support_can_chroot \ support_capture_subprocess \ support_capture_subprocess_check \ + support_check_stat_fd \ + support_check_stat_path \ support_chroot \ support_copy_file \ support_copy_file_range \ @@ -135,8 +133,6 @@ libsupport-routines = \ xgetsockname \ xlisten \ xlseek \ - xlstat \ - xlstat-time64 \ xmalloc \ xmemstream \ xmkdir \ diff --git a/support/support-xfstat-time64.c b/support/support-xfstat-time64.c deleted file mode 100644 index 589a69b..0000000 --- a/support/support-xfstat-time64.c +++ /dev/null @@ -1,32 +0,0 @@ -/* 64-bit time_t stat with error checking. - Copyright (C) 2021-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/>. */ - -/* 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 deleted file mode 100644 index 4519487..0000000 --- a/support/support-xstat-time64.c +++ /dev/null @@ -1,32 +0,0 @@ -/* 64-bit time_t stat with error checking. - Copyright (C) 2021-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/>. */ - -/* 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/support-xstat.c b/support/support-xstat.c deleted file mode 100644 index ce866f7..0000000 --- a/support/support-xstat.c +++ /dev/null @@ -1,30 +0,0 @@ -/* stat64 with error checking. - Copyright (C) 2017-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/>. */ - -/* NB: Non-standard file name to avoid sysdeps override for xstat. */ - -#include <support/check.h> -#include <support/xunistd.h> -#include <sys/stat.h> - -void -xstat (const char *path, struct stat64 *result) -{ - if (stat64 (path, result) != 0) - FAIL_EXIT1 ("stat64 (\"%s\"): %m", path); -} diff --git a/support/xlstat.c b/support/support_check_stat_fd.c index 87df988..4c12adf 100644 --- a/support/xlstat.c +++ b/support/support_check_stat_fd.c @@ -1,5 +1,5 @@ -/* lstat64 with error checking. - Copyright (C) 2017-2024 Free Software Foundation, Inc. +/* Error checking for descriptor-based stat functions. + 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 @@ -18,11 +18,10 @@ #include <support/check.h> #include <support/xunistd.h> -#include <sys/stat.h> void -xlstat (const char *path, struct stat64 *result) +support_check_stat_fd (const char *name, int fd, int result) { - if (lstat64 (path, result) != 0) - FAIL_EXIT1 ("lstat64 (\"%s\"): %m", path); + if (result != 0) + FAIL_EXIT1 ("%s (%d): %m", name, fd); } diff --git a/support/support-xfstat.c b/support/support_check_stat_path.c index ab4b01c..3cf72af 100644 --- a/support/support-xfstat.c +++ b/support/support_check_stat_path.c @@ -1,4 +1,4 @@ -/* fstat64 with error checking. +/* Error checking for path-based stat functions. Copyright (C) 2017-2024 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -18,11 +18,10 @@ #include <support/check.h> #include <support/xunistd.h> -#include <sys/stat.h> void -xfstat (int fd, struct stat64 *result) +support_check_stat_path (const char *name, const char *path, int result) { - if (fstat64 (fd, result) != 0) - FAIL_EXIT1 ("fstat64 (%d): %m", fd); + if (result != 0) + FAIL_EXIT1 ("%s (\"%s\"): %m", name, path); } diff --git a/support/xlstat-time64.c b/support/xlstat-time64.c deleted file mode 100644 index 2bc3ca6..0000000 --- a/support/xlstat-time64.c +++ /dev/null @@ -1,32 +0,0 @@ -/* 64-bit time_t stat with error checking. - Copyright (C) 2021-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/>. */ - -/* 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 cc74c4f..204951b 100644 --- a/support/xunistd.h +++ b/support/xunistd.h @@ -29,7 +29,6 @@ __BEGIN_DECLS -struct stat64; struct statx; pid_t xfork (void); @@ -37,21 +36,20 @@ 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_TIME64_REDIRECTS -# 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 support_check_stat_fd (const char *name, int fd, int result); +void support_check_stat_path (const char *name, const char *path, int result); +#define xstat(path, st) \ + (support_check_stat_path ("stat", (path), stat ((path), (st)))) +#define xfstat(fd, st) \ + (support_check_stat_fd ("fstat", (fd), fstat ((fd), (st)))) +#define xlstat(path, st) \ + (support_check_stat_path ("lstat", (path), lstat ((path), (st)))) +#define xstat64(path, st) \ + (support_check_stat_path ("stat64", (path), stat64 ((path), (st)))) +#define xfstat64(fd, st) \ + (support_check_stat_fd ("fstat64", (fd), fstat64 ((fd), (st)))) +#define xlstat64(path, st) \ + (support_check_stat_path ("lstat64", (path), lstat64 ((path), (st)))) void xstatx (int, const char *, int, unsigned int, struct statx *); void xmkdir (const char *path, mode_t); void xchroot (const char *path); |