add shell-free pipestream
[libi2ncommon] / src / pipestream.hxx
index 9280859..6f83006 100644 (file)
@@ -54,8 +54,15 @@ struct ExecResult
 typedef struct ExecResult ExecResult;
 
 std::string capture_exec(const std::string& command, ExecResult &rescode);
+std::string capture_exec(const char *const *command, ExecResult &rescode);
 
-inline std::string capture_exec(const std::string& command)
+inline std::string capture_exec (const std::string &command)
+{
+    ExecResult r;
+    return capture_exec(command,r);
+}
+
+inline std::string capture_exec(const char *const *command)
 {
     ExecResult r;
     return capture_exec(command,r);
@@ -74,6 +81,7 @@ class inpipebuf : public std::streambuf
 {
 protected:
     char buffer;
+
     FILE *pipe;
 
     // "callback" variables for destructor to store exit status
@@ -82,6 +90,7 @@ protected:
 
 public:
     inpipebuf(const std::string& command);
+    inpipebuf(const char *const *command);
 
     ~inpipebuf();
 
@@ -89,6 +98,9 @@ public:
 
 protected:
     virtual int_type underflow();
+
+private:
+    FILE *init_without_shell (const char *const *argv) const;
 };
 
 /** @brief stream around inpipebuf -- see comment there */
@@ -101,6 +113,9 @@ public:
     inpipestream(const std::string& command)
             : std::istream(&buf), buf(command)
     {}
+    inpipestream(const char *const command[])
+            : std::istream(&buf), buf(command)
+    {}
 
     void store_exit_status(bool *_status_set, int *_exit_status)
     { buf.store_exit_status(_status_set, _exit_status); }