Skip to content

Commit

Permalink
std.io: fix bug when writing large buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Oct 15, 2017
1 parent faf64b5 commit fca1d53
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions std/io.zig
Expand Up @@ -170,7 +170,8 @@ pub const OutStream = struct {
if (self.index == 0)
return;

return self.unbufferedWrite(self.buffer[0..self.index]);
%return self.unbufferedWrite(self.buffer[0..self.index]);
self.index = 0;
}

pub fn close(self: &OutStream) {
Expand Down Expand Up @@ -216,12 +217,10 @@ pub const OutStream = struct {

fn unbufferedWrite(self: &OutStream, bytes: []const u8) -> %void {
if (is_posix) {
%return os.posixWrite(self.fd, self.buffer[0..self.index]);
self.index = 0;
%return os.posixWrite(self.fd, bytes);
} else if (is_windows) {
const handle = %return self.getHandle();
%return os.windowsWrite(handle, self.buffer[0..self.index]);
self.index = 0;
%return os.windowsWrite(handle, bytes);
} else {
@compileError("Unsupported OS");
}
Expand Down

0 comments on commit fca1d53

Please sign in to comment.