| 205 | } |
| 206 | |
| 207 | long long file::size() const { |
| 208 | # ifdef _WIN32 |
| 209 | // Use GetFileSize instead of GetFileSizeEx for the case when _WIN32_WINNT |
| 210 | // is less than 0x0500 as is the case with some default MinGW builds. |
| 211 | // Both functions support large file sizes. |
| 212 | DWORD size_upper = 0; |
| 213 | HANDLE handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd_)); |
| 214 | DWORD size_lower = FMT_SYSTEM(GetFileSize(handle, &size_upper)); |
| 215 | if (size_lower == INVALID_FILE_SIZE) { |
| 216 | DWORD error = GetLastError(); |
| 217 | if (error != NO_ERROR) |
| 218 | FMT_THROW(windows_error(GetLastError(), "cannot get file size")); |
| 219 | } |
| 220 | unsigned long long long_size = size_upper; |
| 221 | return (long_size << sizeof(DWORD) * CHAR_BIT) | size_lower; |
| 222 | # else |
| 223 | using Stat = struct stat; |
| 224 | Stat file_stat = Stat(); |
| 225 | if (FMT_POSIX_CALL(fstat(fd_, &file_stat)) == -1) |
| 226 | FMT_THROW(system_error(errno, "cannot get file attributes")); |
| 227 | static_assert(sizeof(long long) >= sizeof(file_stat.st_size), |
| 228 | "return type of file::size is not large enough"); |
| 229 | return file_stat.st_size; |
| 230 | # endif |
| 231 | } |
| 232 | |
| 233 | std::size_t file::read(void* buffer, std::size_t count) { |
| 234 | RWResult result = 0; |
no test coverage detected