Fix warning about the use of mktemp and make platform agnostic by adding and using PipeBase::CreateWithUniqueName - on behalf of flackr.

http://reviews.llvm.org/D7348

llvm-svn: 228307
diff --git a/lldb/source/Host/windows/PipeWindows.cpp b/lldb/source/Host/windows/PipeWindows.cpp
index 852630e..eccc738 100644
--- a/lldb/source/Host/windows/PipeWindows.cpp
+++ b/lldb/source/Host/windows/PipeWindows.cpp
@@ -9,6 +9,8 @@
 
 #include "lldb/Host/windows/PipeWindows.h"
 
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/raw_ostream.h"
 
 #include <fcntl.h>
@@ -90,6 +92,24 @@
 }
 
 Error
+PipeWindows::CreateWithUniqueName(llvm::StringRef prefix, bool child_process_inherit, llvm::SmallVectorImpl<char>& name)
+{
+    llvm::SmallString<128> pipe_name;
+    Error error;
+    do {
+        pipe_name = prefix;
+        pipe_name += "-";
+        for (unsigned i = 0; i < 6; i++) {
+            pipe_name += "0123456789abcdef"[llvm::sys::Process::GetRandomNumber() & 15];
+        }
+        Error error = CreateNew(pipe_name, child_process_inherit);
+    } while (error.GetError() == ERROR_ALREADY_EXISTS);
+    if (error.Success())
+        name = pipe_name;
+    return error;
+}
+
+Error
 PipeWindows::OpenAsReader(llvm::StringRef name, bool child_process_inherit)
 {
     if (CanRead() || CanWrite())