Skip to contentSkip to conversation

tst_safe_macros: add SAFE_DUP

PATCH New Xiao Yang 2 participants 2 messages Jul 6, 2016 – Jul 11, 2016

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/1 tst_safe_macros: add SAFE_DUP

---
 include/tst_safe_macros.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/tst_safe_macros.h +16 -0
index a213312..540fcb2 100644
@@ -50,6 +50,22 @@
 #define SAFE_DIRNAME(path) \
 	safe_dirname(__FILE__, __LINE__, NULL, (path))
 
+static inline int safe_dup(const char *file, const int lineno,
+			   int oldfd)
+{
+	int rval;
+
+	rval = dup(oldfd);
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			 "dup(%i) failed", oldfd);
+	}
+
+	return rval;
+}
+#define SAFE_DUP(oldfd) \
+	safe_dup(__FILE__, __LINE__, (oldfd))
+
 #define	SAFE_GETCWD(buf, size) \
 	safe_getcwd(__FILE__, __LINE__, NULL, (buf), (size))
 
Signature · 1 line
1.8.3.1