]> granicus.if.org Git - clang/commitdiff
[VFS] Switch from close to SafelyCloseFileDescriptor
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 4 Mar 2016 05:26:14 +0000 (05:26 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 4 Mar 2016 05:26:14 +0000 (05:26 +0000)
The SafelyCloseFileDescriptor machinery does the right thing in the face
of signals while close will do something platform specific which results
in the FD potentially getting leaked.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262687 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/VirtualFileSystem.cpp

index 6977f400287fa78893416fcc61ddeb5128b21993..ba846c841390622758e28b39673cfc7e2220b9f2 100644 (file)
@@ -19,6 +19,7 @@
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/Config/llvm-config.h"
 #include <atomic>
@@ -158,21 +159,10 @@ RealFile::getBuffer(const Twine &Name, int64_t FileSize,
                                    IsVolatile);
 }
 
-// FIXME: This is terrible, we need this for ::close.
-#if !defined(_MSC_VER) && !defined(__MINGW32__)
-#include <unistd.h>
-#include <sys/uio.h>
-#else
-#include <io.h>
-#ifndef S_ISFIFO
-#define S_ISFIFO(x) (0)
-#endif
-#endif
 std::error_code RealFile::close() {
-  if (::close(FD))
-    return std::error_code(errno, std::generic_category());
+  std::error_code EC = sys::Process::SafelyCloseFileDescriptor(FD);
   FD = -1;
-  return std::error_code();
+  return EC;
 }
 
 namespace {