diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-12 16:17:39 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-12 16:17:39 +0100 |
| commit | 3938e6e075867ae3a349ba307ee672aa458d2662 (patch) | |
| tree | 4db5d4c58632519227e535610822f4c8a262c1e4 /lib/Utils/popen_and_save_output.cpp | |
| parent | f93fc8bc4c4db4547ca7fcdd6ad67f73e1755873 (diff) | |
| download | abrt-3938e6e075867ae3a349ba307ee672aa458d2662.tar.gz abrt-3938e6e075867ae3a349ba307ee672aa458d2662.tar.xz abrt-3938e6e075867ae3a349ba307ee672aa458d2662.zip | |
SOSreport.cpp: __gnu_cxx::stdio_filebuf<char> is +8k in code, thanks but no
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'lib/Utils/popen_and_save_output.cpp')
| -rw-r--r-- | lib/Utils/popen_and_save_output.cpp | 30 |
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; +} |
