summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix/PathV2.inc
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2010-12-04 00:32:40 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2010-12-04 00:32:40 +0000
commitdb5576a18525d35bea59875a1b5c5f00ff07cae8 (patch)
tree42979b0a6758607026c71b945a90cd71c0ecb5cd /llvm/lib/Support/Unix/PathV2.inc
parent32a15547da68aeca2b9af9c13d35ad982bebe408 (diff)
downloadbcm5719-llvm-db5576a18525d35bea59875a1b5c5f00ff07cae8.tar.gz
bcm5719-llvm-db5576a18525d35bea59875a1b5c5f00ff07cae8.zip
Support/FileSystem: Add status implementation.
llvm-svn: 120870
Diffstat (limited to 'llvm/lib/Support/Unix/PathV2.inc')
-rw-r--r--llvm/lib/Support/Unix/PathV2.inc32
1 files changed, 32 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/PathV2.inc b/llvm/lib/Support/Unix/PathV2.inc
index d8575bf4e64..f71212f5e6e 100644
--- a/llvm/lib/Support/Unix/PathV2.inc
+++ b/llvm/lib/Support/Unix/PathV2.inc
@@ -277,6 +277,38 @@ error_code file_size(const Twine &path, uint64_t &result) {
return make_error_code(errc::success);
}
+error_code status(const Twine &path, file_status &result) {
+ SmallString<128> path_storage;
+ StringRef p = path.toNullTerminatedStringRef(path_storage);
+
+ struct stat status;
+ if (::stat(p.begin(), &status) != 0) {
+ error_code ec(errno, system_category());
+ if (ec == errc::no_such_file_or_directory)
+ result = file_status(file_type::file_not_found);
+ else
+ result = file_status(file_type::status_error);
+ return ec;
+ }
+
+ if (S_ISDIR(status.st_mode))
+ result = file_status(file_type::directory_file);
+ else if (S_ISREG(status.st_mode))
+ result = file_status(file_type::regular_file);
+ else if (S_ISBLK(status.st_mode))
+ result = file_status(file_type::block_file);
+ else if (S_ISCHR(status.st_mode))
+ result = file_status(file_type::character_file);
+ else if (S_ISFIFO(status.st_mode))
+ result = file_status(file_type::fifo_file);
+ else if (S_ISSOCK(status.st_mode))
+ result = file_status(file_type::socket_file);
+ else
+ result = file_status(file_type::type_unknown);
+
+ return success;
+}
+
error_code unique_file(const Twine &model, int &result_fd,
SmallVectorImpl<char> &result_path) {
SmallString<128> Model;
OpenPOWER on IntegriCloud