Skip to content

Commit

Permalink
Merge pull request #16 from MartinNowak/fix1
Browse files Browse the repository at this point in the history
fix #1 - Windows scattered sync read/write incorrectly implemented
  • Loading branch information
MartinNowak authored Aug 19, 2018
2 parents 9f32c59 + 289244b commit 5a5f610
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/std/io/driver/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ shared @safe @nogc:
{
size_t total;
foreach (b; bufs)
total += read(f, b);
{
immutable len = read(f, b);
total += len;
if (len < b.length)
break;
}
return total;
}
}
Expand Down Expand Up @@ -179,7 +184,12 @@ shared @safe @nogc:
{
size_t total;
foreach (b; bufs)
total += write(f, b);
{
immutable len = write(f, b);
total += len;
if (len < b.length)
break;
}
return total;
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/std/io/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,17 @@ struct File
assert(f.read(buf[$ / 2 .. $], buf[0 .. $ / 2]) == buf.length);
}

@("partial reads")
unittest
{
auto f = File("LICENSE.txt");
ubyte[256] buf = void;
auto len = f.read(buf[$ / 2 .. $], buf[0 .. $ / 2]);
while (len == buf.length)
len = f.read(buf[$ / 2 .. $], buf[0 .. $ / 2]);
assert(len < buf.length);
}

/**
Write buffer content to file.
Expand Down

0 comments on commit 5a5f610

Please sign in to comment.