diff --git a/source/vibe/core/drivers/threadedfile.d b/source/vibe/core/drivers/threadedfile.d index 23d455ad22..b393122fcb 100644 --- a/source/vibe/core/drivers/threadedfile.d +++ b/source/vibe/core/drivers/threadedfile.d @@ -28,8 +28,10 @@ version(Windows){ import std.c.windows.stat; private { - extern(C){ - alias off_t = long; + // TODO: use CreateFile/HANDLE instead of the Posix API on Windows + + extern(C) { + alias off_t = sizediff_t; int open(in char* name, int mode, ...); int chmod(in char* name, int mode); int close(int fd); @@ -142,7 +144,11 @@ final class ThreadedFileStream : FileStream { void seek(ulong offset) { - enforce(.lseek(m_fileDescriptor, offset, SEEK_SET) == offset, "Failed to seek in file."); + version (Win32) { + enforce(offset <= off_t.max, "Cannot seek above 4GB on Windows x32."); + auto pos = .lseek(m_fileDescriptor, cast(off_t)offset, SEEK_SET); + } else auto pos = .lseek(m_fileDescriptor, offset, SEEK_SET); + enforce(pos == offset, "Failed to seek in file."); m_ptr = offset; } @@ -208,3 +214,16 @@ final class ThreadedFileStream : FileStream { flush(); } } + +unittest { // issue #1189 + auto fil = new ThreadedFileStream(Path(".unittest.tmp"), FileMode.createTrunc); + scope (exit) { + fil.close(); + removeFile(".unittest.tmp"); + } + fil.write([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + fil.seek(5); + ubyte[3] buf; + fil.read(buf); + assert(buf == [5, 6, 7]); +}