diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-03 18:49:13 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-03 18:49:13 +0000 |
commit | 376d38753d4208369ab6e4acb4e8769d18c867f6 (patch) | |
tree | 7f334a32ad86240438d8d562479533db4c9a3a0f /llvm/lib/Support/Unix/PathV2.inc | |
parent | ca242f2c366a02d108ae846637614800c1932fca (diff) | |
download | bcm5719-llvm-376d38753d4208369ab6e4acb4e8769d18c867f6.tar.gz bcm5719-llvm-376d38753d4208369ab6e4acb4e8769d18c867f6.zip |
Support/FileSystem: Add equivalent implementation.
llvm-svn: 120827
Diffstat (limited to 'llvm/lib/Support/Unix/PathV2.inc')
-rw-r--r-- | llvm/lib/Support/Unix/PathV2.inc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/PathV2.inc b/llvm/lib/Support/Unix/PathV2.inc index 75cfce822a1..b18023cde76 100644 --- a/llvm/lib/Support/Unix/PathV2.inc +++ b/llvm/lib/Support/Unix/PathV2.inc @@ -238,6 +238,31 @@ error_code exists(const Twine &path, bool &result) { return make_error_code(errc::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; + } + + return make_error_code(errc::success); +} + error_code unique_file(const Twine &model, int &result_fd, SmallVectorImpl<char> &result_path) { SmallString<128> Model; |