| 471 | } |
| 472 | |
| 473 | bool TFileHandle::Flush() noexcept { |
| 474 | if (!IsOpen()) { |
| 475 | return false; |
| 476 | } |
| 477 | #if defined(_win_) |
| 478 | bool ok = ::FlushFileBuffers(Fd_) != 0; |
| 479 | /* |
| 480 | * FlushFileBuffers fails if hFile is a handle to the console output. |
| 481 | * That is because the console output is not buffered. |
| 482 | * The function returns FALSE, and GetLastError returns ERROR_INVALID_HANDLE. |
| 483 | */ |
| 484 | return ok || GetLastError() == ERROR_INVALID_HANDLE; |
| 485 | #elif defined(_unix_) |
| 486 | int ret = ::fsync(Fd_); |
| 487 | |
| 488 | /* |
| 489 | * Ignore EROFS, EINVAL - fd is bound to a special file |
| 490 | * (PIPE, FIFO, or socket) which does not support synchronization. |
| 491 | * Fail in case of EIO, ENOSPC, EDQUOT - data might be lost. |
| 492 | */ |
| 493 | return ret == 0 || errno == EROFS || errno == EINVAL |
| 494 | #if defined(_darwin_) |
| 495 | // ENOTSUP fd does not refer to a vnode |
| 496 | || errno == ENOTSUP |
| 497 | #endif |
| 498 | ; |
| 499 | #else |
| 500 | #error unsupported platform |
| 501 | #endif |
| 502 | } |
| 503 | |
| 504 | bool TFileHandle::FlushData() noexcept { |
| 505 | #if defined(_linux_) |