Signed-off-by: Mats Liljegren <[email protected]>
---
include/safe_stdio.h | 5 +++++
lib/safe_stdio.c | 25 +++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/include/safe_stdio.h b/include/safe_stdio.h
index a4e3da0..b006567 100644
--- a/include/safe_stdio.h
+++ b/include/safe_stdio.h
@@ -36,4 +36,9 @@ int safe_asprintf(const char *file, const int lineno, void
(cleanup_fn)(void),
#define SAFE_ASPRINTF(cleanup_fn, strp, fmt, ...) \
safe_asprintf(__FILE__, __LINE__, cleanup_fn, strp, fmt, __VA_ARGS__)
+FILE *safe_popen(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *command, const char *type);
+#define SAFE_POPEN(cleanup_fn, command, type) \
+ safe_popen(__FILE__, __LINE__, cleanup_fn, command, type)
+
#endif /* __SAFE_STDIO_H__ */
diff --git a/lib/safe_stdio.c b/lib/safe_stdio.c
index d9a2529..b61daa5 100644
--- a/lib/safe_stdio.c
+++ b/lib/safe_stdio.c
@@ -19,6 +19,7 @@
#define _GNU_SOURCE
#include <stdarg.h>
#include <stdio.h>
+#include <errno.h>
#include "test.h"
#include "safe_stdio.h"
@@ -68,3 +69,27 @@ int safe_asprintf(const char *file, const int lineno, void
(cleanup_fn)(void),
return ret;
}
+
+FILE *safe_popen(const char *file, const int lineno, void (cleanup_fn)(void),
+ const char *command, const char *type)
+{
+ FILE *stream;
+ const int saved_errno = errno;
+
+ errno = 0;
+ stream = popen(command, type);
+
+ if (stream == NULL) {
+ if (errno != 0) {
+ tst_brkm(TBROK | TERRNO, cleanup_fn,
+ "%s:%d: popen(%s,%s) failed",
+ file, lineno, command, type);
+ } else {
+ tst_brkm(TBROK, cleanup_fn,
+ "%s:%d: popen(%s,%s) failed: Out of memory",
+ file, lineno, command, type);
+ }
+ }
+
+ errno = saved_errno;
+}
--
1.7.10.4
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list