| 472 | } |
| 473 | |
| 474 | size_t FileIo::size() const { |
| 475 | // Flush and commit only if the file is open for writing |
| 476 | if (p_->fp_ && (p_->openMode_.at(0) != 'r' || p_->openMode_.at(1) == '+')) { |
| 477 | std::fflush(p_->fp_); |
| 478 | #ifdef _MSC_VER |
| 479 | // This is required on msvcrt before stat after writing to a file |
| 480 | _commit(_fileno(p_->fp_)); |
| 481 | #endif |
| 482 | } |
| 483 | |
| 484 | Impl::StructStat buf; |
| 485 | if (p_->stat(buf)) |
| 486 | return std::numeric_limits<size_t>::max(); |
| 487 | return buf.st_size; |
| 488 | } |
| 489 | |
| 490 | int FileIo::open() { |
| 491 | // Default open is in read-only binary mode |