aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/Unix/PathV2.inc
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2010-12-03 18:49:13 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2010-12-03 18:49:13 +0000
commitb531f45a9dca5a2b8cc25d98f2fa9f0ab5955820 (patch)
tree1ee30c72bb3fe6e1171e11efafa536f85f2b0115 /lib/Support/Unix/PathV2.inc
parentdb04b39dad59fa1ae2a15a56ac74ec1628881c65 (diff)
Support/FileSystem: Add equivalent implementation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120827 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Unix/PathV2.inc')
-rw-r--r--lib/Support/Unix/PathV2.inc25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/Support/Unix/PathV2.inc b/lib/Support/Unix/PathV2.inc
index 75cfce822a..b18023cde7 100644
--- a/lib/Support/Unix/PathV2.inc
+++ b/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;