aboutsummaryrefslogtreecommitdiff
path: root/std/io.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-10-15 16:45:43 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-10-15 16:45:43 -0400
commitfcef7c4bb2f8705774b9d53c8f81a8e74cbcb630 (patch)
tree0cc9202dac3d1715d1cd4f02ae899d7a579422a1 /std/io.zig
parentbb169a7b36a658ed463787655df54e3f59133d98 (diff)
downloadzig-fcef7c4bb2f8705774b9d53c8f81a8e74cbcb630.tar.gz
zig-fcef7c4bb2f8705774b9d53c8f81a8e74cbcb630.zip
fix std.io.InStream for windows
now we handle PIPE_BROKEN as an EOF also set up framework for debugging unexpected posix/windows errors
Diffstat (limited to 'std/io.zig')
-rw-r--r--std/io.zig33
1 files changed, 17 insertions, 16 deletions
diff --git a/std/io.zig b/std/io.zig
index 54cefb804c..124e7714da 100644
--- a/std/io.zig
+++ b/std/io.zig
@@ -45,17 +45,12 @@ pub var stderr = OutStream {
/// bug in the program that called the function.
error Invalid;
-/// When an Unexpected error occurs, code that emitted the error likely needs
-/// a patch to recognize the unexpected case so that it can handle it and emit
-/// a more specific error.
-error Unexpected;
-
error DiskQuota;
error FileTooBig;
error Io;
error NoSpaceLeft;
error BadPerm;
-error PipeFail;
+error BrokenPipe;
error BadFd;
error IsDir;
error NotDir;
@@ -207,7 +202,10 @@ pub const OutStream = struct {
if (self.handle) |handle| return handle;
if (system.GetStdHandle(self.handle_id)) |handle| {
if (handle == system.INVALID_HANDLE_VALUE) {
- return error.Unexpected;
+ const err = system.GetLastError();
+ return switch (err) {
+ else => os.unexpectedErrorWindows(err),
+ };
}
self.handle = handle;
return handle;
@@ -292,7 +290,7 @@ pub const InStream = struct {
system.EFAULT => unreachable,
system.EBADF => return error.BadFd,
system.EIO => return error.Io,
- else => return error.Unexpected,
+ else => return os.unexpectedErrorPosix(read_err),
}
}
if (amt_read == 0) return index;
@@ -309,12 +307,12 @@ pub const InStream = struct {
const err = system.GetLastError();
return switch (err) {
system.ERROR.OPERATION_ABORTED => continue,
- system.ERROR.BROKEN_PIPE => error.PipeFail,
- else => error.Unexpected,
+ system.ERROR.BROKEN_PIPE => return index,
+ else => os.unexpectedErrorWindows(err),
};
}
+ if (amt_read == 0) return index;
index += amt_read;
- if (amt_read < want_read_count) return index;
}
return index;
} else {
@@ -374,7 +372,7 @@ pub const InStream = struct {
system.EOVERFLOW => error.Unseekable,
system.ESPIPE => error.Unseekable,
system.ENXIO => error.Unseekable,
- else => error.Unexpected,
+ else => os.unexpectedErrorPosix(err),
};
}
},
@@ -394,7 +392,7 @@ pub const InStream = struct {
system.EOVERFLOW => error.Unseekable,
system.ESPIPE => error.Unseekable,
system.ENXIO => error.Unseekable,
- else => error.Unexpected,
+ else => os.unexpectedErrorPosix(err),
};
}
},
@@ -414,7 +412,7 @@ pub const InStream = struct {
system.EOVERFLOW => error.Unseekable,
system.ESPIPE => error.Unseekable,
system.ENXIO => error.Unseekable,
- else => error.Unexpected,
+ else => os.unexpectedErrorPosix(err),
};
}
return result;
@@ -430,7 +428,7 @@ pub const InStream = struct {
return switch (err) {
system.EBADF => error.BadFd,
system.ENOMEM => error.OutOfMemory,
- else => error.Unexpected,
+ else => os.unexpectedErrorPosix(err),
}
}
@@ -485,7 +483,10 @@ pub const InStream = struct {
if (self.handle) |handle| return handle;
if (system.GetStdHandle(self.handle_id)) |handle| {
if (handle == system.INVALID_HANDLE_VALUE) {
- return error.Unexpected;
+ const err = system.GetLastError();
+ return switch (err) {
+ else => os.unexpectedErrorWindows(err),
+ };
}
self.handle = handle;
return handle;