In FixItRewriteToTemp::RewriteFilename don't try to close the file descriptor
with close(); return it instead.

Fixes mingw build and eliminates possible racing issues.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149043 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Rewrite/FixItRewriter.cpp b/lib/Rewrite/FixItRewriter.cpp
index 5102966..aa57813 100644
--- a/lib/Rewrite/FixItRewriter.cpp
+++ b/lib/Rewrite/FixItRewriter.cpp
@@ -60,18 +60,24 @@
 
   for (iterator I = buffer_begin(), E = buffer_end(); I != E; ++I) {
     const FileEntry *Entry = Rewrite.getSourceMgr().getFileEntryForID(I->first);
-    std::string Filename = FixItOpts->RewriteFilename(Entry->getName());
+    int fd;
+    std::string Filename = FixItOpts->RewriteFilename(Entry->getName(), fd);
     std::string Err;
-    llvm::raw_fd_ostream OS(Filename.c_str(), Err,
-                            llvm::raw_fd_ostream::F_Binary);
+    llvm::OwningPtr<llvm::raw_fd_ostream> OS;
+    if (fd != -1) {
+      OS.reset(new llvm::raw_fd_ostream(fd, /*shouldClose=*/true));
+    } else {
+      OS.reset(new llvm::raw_fd_ostream(Filename.c_str(), Err,
+                                        llvm::raw_fd_ostream::F_Binary));
+    }
     if (!Err.empty()) {
       Diags.Report(clang::diag::err_fe_unable_to_open_output)
           << Filename << Err;
       continue;
     }
     RewriteBuffer &RewriteBuf = I->second;
-    RewriteBuf.write(OS);
-    OS.flush();
+    RewriteBuf.write(*OS);
+    OS->flush();
 
     if (RewrittenFiles)
       RewrittenFiles->push_back(std::make_pair(Entry->getName(), Filename));