mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Fixes lseek for big files on Windows
It was broken in ef69c37f66, before that we were using _lseeki64.
Fixes #8459
This commit is contained in:
parent
7b1d4426aa
commit
cb58116270
3 changed files with 12 additions and 1 deletions
|
|
@ -56,8 +56,14 @@ Status LoadHeightmapImageOs(const OsPath& filepath, std::vector<u16>& heightmap)
|
|||
File file;
|
||||
RETURN_STATUS_IF_ERR(file.Open(OsString(filepath), O_RDONLY));
|
||||
|
||||
#if OS_WIN
|
||||
// sizeof(long) == 4 on Windows so we can't use lseek.
|
||||
size_t fileSize = _lseeki64(file.Descriptor(), 0, SEEK_END);
|
||||
_lseeki64(file.Descriptor(), 0, SEEK_SET);
|
||||
#else
|
||||
size_t fileSize = lseek(file.Descriptor(), 0, SEEK_END);
|
||||
lseek(file.Descriptor(), 0, SEEK_SET);
|
||||
#endif
|
||||
|
||||
std::shared_ptr<u8> fileData;
|
||||
RETURN_STATUS_IF_ERR(AllocateAligned(fileData, fileSize, maxSectorSize));
|
||||
|
|
|
|||
|
|
@ -51,7 +51,12 @@ Status Issue(aiocb& cb, [[maybe_unused]] size_t queueDepth)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
#if OS_WIN
|
||||
// sizeof(long) == 4 on Windows so we can't use lseek.
|
||||
ENSURE(_lseeki64(cb.aio_fildes, cb.aio_offset, SEEK_SET) == cb.aio_offset);
|
||||
#else
|
||||
ENSURE(lseek(cb.aio_fildes, cb.aio_offset, SEEK_SET) == cb.aio_offset);
|
||||
#endif
|
||||
|
||||
void* buf = (void*)cb.aio_buf; // cast from volatile void*
|
||||
const ssize_t bytesTransferred = (cb.aio_lio_opcode == LIO_WRITE)? write(cb.aio_fildes, buf, cb.aio_nbytes) : read(cb.aio_fildes, buf, cb.aio_nbytes);
|
||||
|
|
|
|||
|
|
@ -53,6 +53,6 @@ typedef unsigned int mode_t; // defined by MinGW but not VC
|
|||
#define S_ISREG(m) (m & S_IFREG)
|
||||
|
||||
|
||||
#include <corecrt_io.h> // read, write, lseek
|
||||
#include <corecrt_io.h> // read, write
|
||||
|
||||
#endif // #ifndef INCLUDED_WFILESYSTEM
|
||||
|
|
|
|||
Loading…
Reference in a new issue