| 228 | } |
| 229 | |
| 230 | i64 GetFileLength(FHANDLE fd) { |
| 231 | #if defined(_win_) |
| 232 | LARGE_INTEGER pos; |
| 233 | if (!::GetFileSizeEx(fd, &pos)) { |
| 234 | return -1L; |
| 235 | } |
| 236 | return pos.QuadPart; |
| 237 | #elif defined(_unix_) |
| 238 | struct stat statbuf; |
| 239 | if (::fstat(fd, &statbuf) != 0) { |
| 240 | return -1L; |
| 241 | } |
| 242 | if (!(statbuf.st_mode & (S_IFREG | S_IFBLK | S_IFCHR))) { |
| 243 | // st_size only makes sense for regular files or devices |
| 244 | errno = EINVAL; |
| 245 | return -1L; |
| 246 | } |
| 247 | return statbuf.st_size; |
| 248 | #else |
| 249 | #error unsupported platform |
| 250 | #endif |
| 251 | } |
| 252 | |
| 253 | i64 GetFileLength(const char* name) { |
| 254 | #if defined(_win_) |
no test coverage detected