[LTP] [PATCH v4 2/3] tst_safe_file_at: Add SAFE_FSTATAT macro
Yang Xu
xuyang2018.jy@fujitsu.com
Wed Sep 14 10:12:21 CEST 2022
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
include/tst_safe_file_at.h | 7 +++++++
lib/tst_safe_file_at.c | 20 ++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/include/tst_safe_file_at.h b/include/tst_safe_file_at.h
index e253198e6..082a5acd9 100644
--- a/include/tst_safe_file_at.h
+++ b/include/tst_safe_file_at.h
@@ -29,6 +29,9 @@
safe_fchownat(__FILE__, __LINE__, \
(dirfd), (path), (owner), (group), (flags))
+#define SAFE_FSTATAT(dirfd, path, statbuf, flags) \
+ safe_fstatat(__FILE__, __LINE__, (dirfd), (path), (statbuf), (flags))
+
const char *tst_decode_fd(const int fd)
__attribute__((warn_unused_result));
@@ -67,4 +70,8 @@ int safe_fchownat(const char *const file, const int lineno,
gid_t group, int flags)
__attribute__ ((nonnull));
+int safe_fstatat(const char *const file, const int lineno,
+ const int dirfd, const char *const path, struct stat *statbuf,
+ int flags)
+ __attribute__ ((nonnull));
#endif
diff --git a/lib/tst_safe_file_at.c b/lib/tst_safe_file_at.c
index 6370a68e5..f530dc349 100644
--- a/lib/tst_safe_file_at.c
+++ b/lib/tst_safe_file_at.c
@@ -215,3 +215,23 @@ int safe_fchownat(const char *const file, const int lineno,
return rval;
}
+
+int safe_fstatat(const char *const file, const int lineno,
+ const int dirfd, const char *const path, struct stat *statbuf, int flags)
+{
+ int rval;
+
+ rval = fstatat(dirfd, path, statbuf, flags);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "fstatat(%d<%s>, '%s', %p, %d) failed", dirfd,
+ tst_decode_fd(dirfd), path, statbuf, flags);
+ } else if (rval) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid fstatat(%d<%s>, '%s', %p, %d) return value %d",
+ dirfd, tst_decode_fd(dirfd), path, statbuf, flags, rval);
+ }
+
+ return rval;
+}
--
2.23.0
More information about the ltp
mailing list