* this function tries to make a particular range of a file allocated (corresponding to disk space) * it is advisory, and the range specified in the arguments will never contain live data */
| 651 | * it is advisory, and the range specified in the arguments will never contain live data |
| 652 | */ |
| 653 | void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) { |
| 654 | #if defined(WIN32) |
| 655 | // Windows-specific version |
| 656 | HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(file)); |
| 657 | LARGE_INTEGER nFileSize; |
| 658 | int64_t nEndPos = (int64_t)offset + length; |
| 659 | nFileSize.u.LowPart = nEndPos & 0xFFFFFFFF; |
| 660 | nFileSize.u.HighPart = nEndPos >> 32; |
| 661 | SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN); |
| 662 | SetEndOfFile(hFile); |
| 663 | #elif defined(MAC_OSX) |
| 664 | // OSX specific version |
| 665 | fstore_t fst; |
| 666 | fst.fst_flags = F_ALLOCATECONTIG; |
| 667 | fst.fst_posmode = F_PEOFPOSMODE; |
| 668 | fst.fst_offset = 0; |
| 669 | fst.fst_length = (off_t)offset + length; |
| 670 | fst.fst_bytesalloc = 0; |
| 671 | if (fcntl(fileno(file), F_PREALLOCATE, &fst) == -1) { |
| 672 | fst.fst_flags = F_ALLOCATEALL; |
| 673 | fcntl(fileno(file), F_PREALLOCATE, &fst); |
| 674 | } |
| 675 | ftruncate(fileno(file), fst.fst_length); |
| 676 | #elif defined(__linux__) |
| 677 | // Version using posix_fallocate |
| 678 | off_t nEndPos = (off_t)offset + length; |
| 679 | posix_fallocate(fileno(file), 0, nEndPos); |
| 680 | #else |
| 681 | // Fallback version |
| 682 | // TODO: just write one byte per block |
| 683 | static const char buf[65536] = {}; |
| 684 | fseek(file, offset, SEEK_SET); |
| 685 | while (length > 0) { |
| 686 | unsigned int now = 65536; |
| 687 | if (length < now) |
| 688 | now = length; |
| 689 | fwrite(buf, 1, now, file); // allowed to fail; this function is advisory anyway |
| 690 | length -= now; |
| 691 | } |
| 692 | #endif |
| 693 | } |
| 694 | |
| 695 | void ShrinkDebugFile() |
| 696 | { |
no outgoing calls
no test coverage detected