aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-29 21:26:49 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-29 21:26:49 +0000
commit3ed45fe2be4356351942a2cfe9bd92e996d4fcad (patch)
treedb0f4e0ca1ab5bea02dd42f312770d37b539a1e7 /lib/Support
parent096880b59008a44860edd0fcab1f55aa1363bdf5 (diff)
downloadexternal_llvm-3ed45fe2be4356351942a2cfe9bd92e996d4fcad.zip
external_llvm-3ed45fe2be4356351942a2cfe9bd92e996d4fcad.tar.gz
external_llvm-3ed45fe2be4356351942a2cfe9bd92e996d4fcad.tar.bz2
Include st_dev to make the result of getUniqueID actually unique.
This will let us use getUniqueID instead of st_dev directly on clang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187378 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/Path.cpp9
-rw-r--r--lib/Support/Unix/Path.inc16
-rw-r--r--lib/Support/Windows/Path.inc27
3 files changed, 21 insertions, 31 deletions
diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp
index 6d10c0e..cfd9ed6 100644
--- a/lib/Support/Path.cpp
+++ b/lib/Support/Path.cpp
@@ -638,6 +638,15 @@ bool is_relative(const Twine &path) {
namespace fs {
+error_code getUniqueID(const Twine Path, UniqueID &Result) {
+ file_status Status;
+ error_code EC = status(Path, Status);
+ if (EC)
+ return EC;
+ Result = Status.getUniqueID();
+ return error_code::success();
+}
+
error_code createUniqueFile(const Twine &Model, int &ResultFd,
SmallVectorImpl<char> &ResultPath, unsigned Mode) {
return createUniqueEntity(Model, ResultFd, ResultPath, false, Mode, FS_File);
diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc
index 5386366..0c4518c 100644
--- a/lib/Support/Unix/Path.inc
+++ b/lib/Support/Unix/Path.inc
@@ -293,6 +293,10 @@ TimeValue file_status::getLastModificationTime() const {
return Ret;
}
+UniqueID file_status::getUniqueID() {
+ return UniqueID(fs_st_dev, fs_st_ino);
+}
+
error_code current_path(SmallVectorImpl<char> &result) {
#ifdef MAXPATHLEN
result.reserve(MAXPATHLEN);
@@ -457,18 +461,6 @@ error_code equivalent(const Twine &A, const Twine &B, bool &result) {
return error_code::success();
}
-error_code getUniqueID(const Twine Path, uint64_t &Result) {
- SmallString<128> Storage;
- StringRef P = Path.toNullTerminatedStringRef(Storage);
-
- struct stat Status;
- if (::stat(P.begin(), &Status) != 0)
- return error_code(errno, system_category());
-
- Result = Status.st_ino;
- return error_code::success();
-}
-
static error_code fillStatus(int StatRet, const struct stat &Status,
file_status &Result) {
if (StatRet != 0) {
diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc
index 9936343..f3460e4 100644
--- a/lib/Support/Windows/Path.inc
+++ b/lib/Support/Windows/Path.inc
@@ -269,6 +269,14 @@ std::string getMainExecutable(const char *argv0, void *MainExecAddr) {
return ret != MAX_PATH ? pathname : "";
}
+UniqueID file_status::getUniqueID() {
+ // The file is uniquely identified by the volume serial number along
+ // with the 64-bit file identifier.
+ uint64_t FileID = (static_cast<uint64_t>(FileIndexHigh) << 32ULL) |
+ static_cast<uint64_t>(FileIndexLow);
+
+ return UniqueID(VolumeSerialNumber, FileID);
+}
TimeValue file_status::getLastModificationTime() const {
ULARGE_INTEGER UI;
@@ -533,25 +541,6 @@ error_code equivalent(const Twine &A, const Twine &B, bool &result) {
return error_code::success();
}
-error_code getUniqueID(const Twine Path, uint64_t &Result) {
- file_status Status;
- if (error_code E = status(Path, Status))
- return E;
-
- // The file is uniquely identified by the volume serial number along
- // with the 64-bit file identifier.
- Result = (static_cast<uint64_t>(Status.FileIndexHigh) << 32ULL) |
- static_cast<uint64_t>(Status.FileIndexLow);
-
- // Because the serial number is 32-bits, but we've already used up all 64
- // bits for the file index, XOR the serial number into the high 32 bits of
- // the resulting value. We could potentially get collisons from this, but
- // the likelihood is low.
- Result ^= (static_cast<uint64_t>(Status.VolumeSerialNumber) << 32ULL);
-
- return error_code::success();
-}
-
static bool isReservedName(StringRef path) {
// This list of reserved names comes from MSDN, at:
// http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx