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
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;
#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...
uint32_t getGroup() const {
return 9999; // Not applicable to Windows, so...
}
+ uint64_t getSize() const {
+ return (uint64_t(FileSizeHigh) << 32) + FileSizeLow;
+ }
#endif
// setters
/// @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?
///
return error_code::success();
}
-error_code file_size(const Twine &path, uint64_t &result) {
- SmallString<128> path_storage;
- StringRef p = path.toNullTerminatedStringRef(path_storage);
-
- struct stat status;
- if (::stat(p.begin(), &status) == -1)
- return error_code(errno, system_category());
- if (!S_ISREG(status.st_mode))
- return make_error_code(errc::operation_not_permitted);
-
- result = status.st_size;
- return error_code::success();
-}
-
error_code getUniqueID(const Twine Path, uint64_t &Result) {
SmallString<128> Storage;
StringRef P = Path.toNullTerminatedStringRef(Storage);
result.fs_st_mtime = status.st_mtime;
result.fs_st_uid = status.st_uid;
result.fs_st_gid = status.st_gid;
+ result.fs_st_size = status.st_size;
return error_code::success();
}
return error_code::success();
}
-error_code file_size(const Twine &path, uint64_t &result) {
- SmallString<128> path_storage;
- SmallVector<wchar_t, 128> path_utf16;
-
- if (error_code ec = UTF8ToUTF16(path.toStringRef(path_storage),
- path_utf16))
- return ec;
-
- WIN32_FILE_ATTRIBUTE_DATA FileData;
- if (!::GetFileAttributesExW(path_utf16.begin(),
- ::GetFileExInfoStandard,
- &FileData))
- return windows_error(::GetLastError());
-
- result =
- (uint64_t(FileData.nFileSizeHigh) << (sizeof(FileData.nFileSizeLow) * 8))
- + FileData.nFileSizeLow;
-
- return error_code::success();
-}
-
error_code getUniqueID(const Twine Path, uint64_t &Result) {
file_status Status;
if (error_code E = status(Path, Status))