| 388 | } |
| 389 | |
| 390 | bool TFileHandle::Resize(i64 length) noexcept { |
| 391 | if (!IsOpen()) { |
| 392 | return false; |
| 393 | } |
| 394 | i64 currentLength = GetLength(); |
| 395 | if (length == currentLength) { |
| 396 | return true; |
| 397 | } |
| 398 | #if defined(_win_) |
| 399 | i64 currentPosition = GetPosition(); |
| 400 | if (currentPosition == -1L) { |
| 401 | return false; |
| 402 | } |
| 403 | Seek(length, sSet); |
| 404 | if (!::SetEndOfFile(Fd_)) { |
| 405 | return false; |
| 406 | } |
| 407 | if (currentPosition < length) { |
| 408 | Seek(currentPosition, sSet); |
| 409 | } |
| 410 | return true; |
| 411 | #elif defined(_unix_) |
| 412 | return (0 == ftruncate(Fd_, (off_t)length)); |
| 413 | #else |
| 414 | #error unsupported platform |
| 415 | #endif |
| 416 | } |
| 417 | |
| 418 | bool TFileHandle::Reserve(i64 length) noexcept { |
| 419 | // FIXME this should reserve disk space with fallocate |