diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-10 17:16:40 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-10 17:16:40 +0000 |
commit | ac2de33d2aaa076dc54ce2cea675bcca5b50261e (patch) | |
tree | e6e772d229275c7201d1c3afa62097f0931a115a /include/llvm/Support/FileSystem.h | |
parent | 43ae5e85f829df883dd364c0b9612bbe90f3ad97 (diff) | |
download | external_llvm-ac2de33d2aaa076dc54ce2cea675bcca5b50261e.zip external_llvm-ac2de33d2aaa076dc54ce2cea675bcca5b50261e.tar.gz external_llvm-ac2de33d2aaa076dc54ce2cea675bcca5b50261e.tar.bz2 |
Use status to implement file_size.
The status function is already using a syscall that returns the file size.
Remember it and implement file_size as a simple wrapper.
No functionally change, but clients that already use status now can avoid
calling file_size.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186016 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/FileSystem.h')
-rw-r--r-- | include/llvm/Support/FileSystem.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/include/llvm/Support/FileSystem.h b/include/llvm/Support/FileSystem.h index 8380d50..df37379 100644 --- a/include/llvm/Support/FileSystem.h +++ b/include/llvm/Support/FileSystem.h @@ -153,6 +153,7 @@ class file_status time_t fs_st_mtime; uid_t fs_st_uid; gid_t fs_st_gid; + off_t fs_st_size; #elif defined (LLVM_ON_WIN32) uint32_t LastWriteTimeHigh; uint32_t LastWriteTimeLow; @@ -180,6 +181,7 @@ public: #if defined(LLVM_ON_UNIX) uint32_t getUser() const { return fs_st_uid; } uint32_t getGroup() const { return fs_st_gid; } + uint64_t getSize() const { return fs_st_size; } #elif defined (LLVM_ON_WIN32) uint32_t getUser() const { return 9999; // Not applicable to Windows, so... @@ -187,6 +189,9 @@ public: uint32_t getGroup() const { return 9999; // Not applicable to Windows, so... } + uint64_t getSize() const { + return (uint64_t(FileSizeHigh) << 32) + FileSizeLow; + } #endif // setters @@ -435,7 +440,14 @@ inline bool equivalent(const Twine &A, const Twine &B) { /// @param result Set to the size of the file in \a path. /// @returns errc::success if result has been successfully set, otherwise a /// platform specific error_code. -error_code file_size(const Twine &path, uint64_t &result); +inline error_code file_size(const Twine &Path, uint64_t &Result) { + file_status Status; + error_code EC = status(Path, Status); + if (EC) + return EC; + Result = Status.getSize(); + return error_code::success(); +} /// @brief Does status represent a directory? /// |