Skip to content

Commit

Permalink
Fix signature of lseek on Win32. Fixes #1189.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Jul 18, 2015
1 parent 6963501 commit 3262318
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions source/vibe/core/drivers/threadedfile.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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]);
}

0 comments on commit 3262318

Please sign in to comment.