[libFuzzer] Encapsulate commands in a class.

Summary:
To be more portable (especially w.r.t. platforms without system()),
commands should be managed programmatically rather than via string
manipulation on the command line. This change introduces
Fuzzer::Command, with methods to manage arguments and flags, set output
options, and execute the command.

Patch By: aarongreen

Reviewers: kcc, morehouse

Reviewed By: kcc, morehouse

Subscribers: llvm-commits, mgorny

Differential Revision: https://reviews.llvm.org/D40103

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/fuzzer@319680 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/FuzzerUtilDarwin.cpp b/FuzzerUtilDarwin.cpp
index 2df4872..4bfbc11 100644
--- a/FuzzerUtilDarwin.cpp
+++ b/FuzzerUtilDarwin.cpp
@@ -10,7 +10,7 @@
 //===----------------------------------------------------------------------===//
 #include "FuzzerDefs.h"
 #if LIBFUZZER_APPLE
-
+#include "FuzzerCommand.h"
 #include "FuzzerIO.h"
 #include <mutex>
 #include <signal.h>
@@ -38,7 +38,8 @@
 // signal handlers when the first thread enters and restores them when the last
 // thread finishes execution of the function and ensures this is not racey by
 // using a mutex.
-int ExecuteCommand(const std::string &Command) {
+int ExecuteCommand(const Command &Cmd) {
+  std::string CmdLine = Cmd.toString();
   posix_spawnattr_t SpawnAttributes;
   if (posix_spawnattr_init(&SpawnAttributes))
     return -1;
@@ -98,7 +99,7 @@
 
   pid_t Pid;
   char **Environ = environ; // Read from global
-  const char *CommandCStr = Command.c_str();
+  const char *CommandCStr = CmdLine.c_str();
   char *const Argv[] = {
     strdup("sh"),
     strdup("-c"),