summaryrefslogtreecommitdiffstats
path: root/lib/Utils/popen_and_save_output.cpp
diff options
context:
space:
mode:
authorKarel Klic <kklic@redhat.com>2009-11-12 16:58:07 +0100
committerKarel Klic <kklic@redhat.com>2009-11-12 16:58:07 +0100
commit32cee84a34c005fe0d2863f439007ec633687fa8 (patch)
tree149ca7014e4295de3788f28ae88e9d9d7003da46 /lib/Utils/popen_and_save_output.cpp
parent5a8a8a6c99c9067e0dfcce839c32826a2badff0b (diff)
parent3938e6e075867ae3a349ba307ee672aa458d2662 (diff)
downloadabrt-32cee84a34c005fe0d2863f439007ec633687fa8.tar.gz
abrt-32cee84a34c005fe0d2863f439007ec633687fa8.tar.xz
abrt-32cee84a34c005fe0d2863f439007ec633687fa8.zip
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'lib/Utils/popen_and_save_output.cpp')
-rw-r--r--lib/Utils/popen_and_save_output.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/Utils/popen_and_save_output.cpp b/lib/Utils/popen_and_save_output.cpp
new file mode 100644
index 0000000..4bcbcac
--- /dev/null
+++ b/lib/Utils/popen_and_save_output.cpp
@@ -0,0 +1,30 @@
+/*
+ * Utility routines.
+ *
+ * Licensed under GPLv2 or later, see file COPYING in this tarball for details.
+ */
+#include "abrtlib.h"
+
+using namespace std;
+
+string popen_and_save_output(const char *cmd)
+{
+ string result;
+
+ FILE *fp = popen(cmd, "r");
+ if (fp == NULL) /* fork or pipe failed; or out-of-mem */
+ {
+ return result;
+ }
+
+ size_t sz;
+ char buf[BUFSIZ + 1];
+ while ((sz = fread(buf, 1, sizeof(buf)-1, fp)) > 0)
+ {
+ buf[sz] = '\0';
+ result += buf;
+ }
+ pclose(fp);
+
+ return result;
+}