>From 5b93defc971e389ccf6025a5d23735a68f77ac38 Mon Sep 17 00:00:00 2001
From: Zeng Linggang <[email protected]>
Date: Thu, 5 Dec 2013 19:54:28 +0800
Subject: [PATCH] add SAFE_FSTAT macro

Signed-off-by: Zeng Linggang <[email protected]>
---
 include/safe_macros.h |  5 +++++
 lib/safe_macros.c     | 15 +++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/include/safe_macros.h b/include/safe_macros.h
index adf4d09..1a6acdd 100644
--- a/include/safe_macros.h
+++ b/include/safe_macros.h
@@ -175,5 +175,10 @@ long safe_sysconf(const char *file, const int lineno,
 #define SAFE_SYSCONF(cleanup_fn, name) \
        safe_sysconf(__FILE__, __LINE__, cleanup_fn, name)
 
+int safe_fstat(const char *file, const int lineno, void (cleanup_fn)(void),
+              int fd, struct stat *buf);
+#define SAFE_FSTAT(cleanup_fn, fd, buf) \
+       safe_fstat(__FILE__, __LINE__, (cleanup_fn), (fd), (buf))
+
 #endif /* __SAFE_MACROS_H__ */
 #endif /* __TEST_H__ */
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index 4da9914..dea8241 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -438,3 +438,18 @@ long safe_sysconf(const char *file, const int lineno,
 
        return rval;
 }
+
+int safe_fstat(const char *file, const int lineno,
+              void (cleanup_fn)(void), int fd, struct stat *buf)
+{
+       int rval;
+
+       rval = fstat(fd, buf);
+
+       if (rval == -1) {
+               tst_brkm(TBROK | TERRNO, cleanup_fn,
+                        "fstat  failed at %s:%d", file, lineno);
+       }
+
+       return rval;
+}
-- 
1.8.2.1




------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to