diff options
author | Reid Kleckner <reid@kleckner.net> | 2013-08-06 22:51:21 +0000 |
---|---|---|
committer | Reid Kleckner <reid@kleckner.net> | 2013-08-06 22:51:21 +0000 |
commit | 47cfec02842f885b46ea0d3c812793e660691640 (patch) | |
tree | 5f1f2fb5d7b3fbc2dc7e66be64a165b75f654ec2 /lib/Support/LockFileManager.cpp | |
parent | 2d66d4cf42022239bfc9cd260a7b924400139cb5 (diff) | |
download | llvm-47cfec02842f885b46ea0d3c812793e660691640.tar.gz llvm-47cfec02842f885b46ea0d3c812793e660691640.tar.bz2 llvm-47cfec02842f885b46ea0d3c812793e660691640.tar.xz |
Remove some std stream usage from Support and TableGen
LLVM's coding standards recommend raw_ostream and MemoryBuffer for
reading and writing text.
This has the side effect of allowing clang to compile more of Support
and TableGen in the Microsoft C++ ABI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187826 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/LockFileManager.cpp')
-rw-r--r-- | lib/Support/LockFileManager.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp index 21c4d4070d..b1ff22c2e6 100644 --- a/lib/Support/LockFileManager.cpp +++ b/lib/Support/LockFileManager.cpp @@ -7,9 +7,11 @@ // //===----------------------------------------------------------------------===// #include "llvm/Support/LockFileManager.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" -#include <fstream> #include <sys/stat.h> #include <sys/types.h> #if LLVM_ON_WIN32 @@ -35,16 +37,18 @@ LockFileManager::readLockFile(StringRef LockFileName) { // Read the owning host and PID out of the lock file. If it appears that the // owning process is dead, the lock file is invalid. - int PID = 0; - std::string Hostname; - std::ifstream Input(LockFileName.str().c_str()); - if (Input >> Hostname >> PID && PID > 0 && - processStillExecuting(Hostname, PID)) - return std::make_pair(Hostname, PID); + OwningPtr<MemoryBuffer> MB; + if (MemoryBuffer::getFile(LockFileName, MB)) { + StringRef Hostname; + StringRef PIDStr; + tie(Hostname, PIDStr) = getToken(MB->getBuffer(), " "); + int PID; + if (PIDStr.getAsInteger(10, PID)) + return std::make_pair(std::string(Hostname), PID); + } // Delete the lock file. It's invalid anyway. - bool Existed; - sys::fs::remove(LockFileName, Existed); + sys::fs::remove(LockFileName); return None; } |