| 510 | |
| 511 | |
| 512 | uint64 CFile::GetAvailable() const |
| 513 | { |
| 514 | // Lock around both calls so length/position are taken atomically; |
| 515 | // otherwise a concurrent write could land between and skew the |
| 516 | // reported "available" count. Recursive so the inner GetLength / |
| 517 | // GetPosition calls (which lock again) don't deadlock. |
| 518 | std::lock_guard<std::recursive_mutex> lock(m_mutex); |
| 519 | |
| 520 | const uint64 length = GetLength(); |
| 521 | const uint64 position = GetPosition(); |
| 522 | |
| 523 | // Safely handle seeking past EOF |
| 524 | if (position < length) { |
| 525 | return length - position; |
| 526 | } |
| 527 | |
| 528 | // File is at or after EOF |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | |
| 533 | bool CFile::SetLength(uint64 new_len) |