diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2011-12-12 06:04:28 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2011-12-12 06:04:28 +0000 |
commit | d45fbe62270eaf826419b93f1da66f1850f37faf (patch) | |
tree | 0201ac7435851c79ad95e82f1bd9108feacdc160 /lib/Support/Unix/PathV2.inc | |
parent | c3b00e80400d27d5d6152374d87c0ad5866c780c (diff) | |
download | external_llvm-d45fbe62270eaf826419b93f1da66f1850f37faf.zip external_llvm-d45fbe62270eaf826419b93f1da66f1850f37faf.tar.gz external_llvm-d45fbe62270eaf826419b93f1da66f1850f37faf.tar.bz2 |
Support/FileSystem: Implement bool equivalent(file_status A, file_status B);
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146364 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Unix/PathV2.inc')
-rw-r--r-- | lib/Support/Unix/PathV2.inc | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/lib/Support/Unix/PathV2.inc b/lib/Support/Unix/PathV2.inc index 41ed49f..2a21c14 100644 --- a/lib/Support/Unix/PathV2.inc +++ b/lib/Support/Unix/PathV2.inc @@ -273,28 +273,17 @@ error_code exists(const Twine &path, bool &result) { return success; } -error_code equivalent(const Twine &A, const Twine &B, bool &result) { - // Get arguments. - SmallString<128> a_storage; - SmallString<128> b_storage; - StringRef a = A.toNullTerminatedStringRef(a_storage); - StringRef b = B.toNullTerminatedStringRef(b_storage); - - struct stat stat_a, stat_b; - int error_b = ::stat(b.begin(), &stat_b); - int error_a = ::stat(a.begin(), &stat_a); - - // If both are invalid, it's an error. If only one is, the result is false. - if (error_a != 0 || error_b != 0) { - if (error_a == error_b) - return error_code(errno, system_category()); - result = false; - } else { - result = - stat_a.st_dev == stat_b.st_dev && - stat_a.st_ino == stat_b.st_ino; - } +bool equivalent(file_status A, file_status B) { + assert(status_known(A) && status_known(B)); + return A.st_dev == B.st_dev && + A.st_ino == B.st_ino; +} +error_code equivalent(const Twine &A, const Twine &B, bool &result) { + file_status fsA, fsB; + if (error_code ec = status(A, fsA)) return ec; + if (error_code ec = status(B, fsB)) return ec; + result = equivalent(fsA, fsB); return success; } @@ -341,6 +330,9 @@ error_code status(const Twine &path, file_status &result) { else result = file_status(file_type::type_unknown); + result.st_dev = status.st_dev; + result.st_ino = status.st_ino; + return success; } |