Fix file pointer management in FileStream. Fixes rejectedsoftware/vibe.d#1684.
This commit is contained in:
parent
d07e9258d9
commit
68430a1ea4
|
@ -464,6 +464,7 @@ struct FileStream {
|
||||||
cb => eventDriver.files.read(m_fd, ctx.ptr, dst, mode, cb),
|
cb => eventDriver.files.read(m_fd, ctx.ptr, dst, mode, cb),
|
||||||
cb => eventDriver.files.cancelRead(m_fd)
|
cb => eventDriver.files.cancelRead(m_fd)
|
||||||
);
|
);
|
||||||
|
ctx.ptr += res[2];
|
||||||
enforce(res[1] == IOStatus.ok, "Failed to read data from disk.");
|
enforce(res[1] == IOStatus.ok, "Failed to read data from disk.");
|
||||||
return res[2];
|
return res[2];
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,16 +12,23 @@ void main()
|
||||||
{
|
{
|
||||||
auto f = openFile("test.dat", FileMode.createTrunc);
|
auto f = openFile("test.dat", FileMode.createTrunc);
|
||||||
assert(f.size == 0);
|
assert(f.size == 0);
|
||||||
|
assert(f.tell == 0);
|
||||||
f.write(bytes!(1, 2, 3, 4, 5));
|
f.write(bytes!(1, 2, 3, 4, 5));
|
||||||
assert(f.size == 5);
|
assert(f.size == 5);
|
||||||
|
assert(f.tell == 5);
|
||||||
f.seek(0);
|
f.seek(0);
|
||||||
|
assert(f.tell == 0);
|
||||||
f.write(bytes!(1, 2, 3, 4, 5));
|
f.write(bytes!(1, 2, 3, 4, 5));
|
||||||
assert(f.size == 5);
|
assert(f.size == 5);
|
||||||
|
assert(f.tell == 5);
|
||||||
f.write(bytes!(6, 7, 8, 9, 10));
|
f.write(bytes!(6, 7, 8, 9, 10));
|
||||||
assert(f.size == 10);
|
assert(f.size == 10);
|
||||||
|
assert(f.tell == 10);
|
||||||
ubyte[5] dst;
|
ubyte[5] dst;
|
||||||
f.seek(2);
|
f.seek(2);
|
||||||
|
assert(f.tell == 2);
|
||||||
f.read(dst);
|
f.read(dst);
|
||||||
|
assert(f.tell == 7);
|
||||||
assert(dst[] == bytes!(3, 4, 5, 6, 7));
|
assert(dst[] == bytes!(3, 4, 5, 6, 7));
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue