aboutsummaryrefslogtreecommitdiff
path: root/std/io.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-02-02 18:13:32 -0500
committerAndrew Kelley <superjoe30@gmail.com>2018-02-02 18:13:32 -0500
commitb8f59e14cdbf90cf724ed9e721c1909293f41b3b (patch)
treeef7a9f2b4534f691e6284b16218c354654abb9e5 /std/io.zig
parent39d5f44863aafa77163b2a7e32f2553a589dbb2c (diff)
downloadzig-b8f59e14cdbf90cf724ed9e721c1909293f41b3b.tar.gz
zig-b8f59e14cdbf90cf724ed9e721c1909293f41b3b.zip
*WIP* error sets - correctly resolve inferred error sets
Diffstat (limited to 'std/io.zig')
-rw-r--r--std/io.zig8
1 files changed, 6 insertions, 2 deletions
diff --git a/std/io.zig b/std/io.zig
index e110d4ddf5..dbca37745a 100644
--- a/std/io.zig
+++ b/std/io.zig
@@ -102,12 +102,14 @@ pub const File = struct {
/// The OS-specific file descriptor or file handle.
handle: os.FileHandle,
+ const OpenError = os.WindowsOpenError || os.PosixOpenError;
+
/// `path` may need to be copied in memory to add a null terminating byte. In this case
/// a fixed size buffer of size std.os.max_noalloc_path_len is an attempted solution. If the fixed
/// size buffer is too small, and the provided allocator is null, error.NameTooLong is returned.
/// otherwise if the fixed size buffer is too small, allocator is used to obtain the needed memory.
/// Call close to clean up.
- pub fn openRead(path: []const u8, allocator: ?&mem.Allocator) !File {
+ pub fn openRead(path: []const u8, allocator: ?&mem.Allocator) OpenError!File {
if (is_posix) {
const flags = system.O_LARGEFILE|system.O_RDONLY;
const fd = try os.posixOpen(path, flags, 0, allocator);
@@ -338,7 +340,9 @@ pub const File = struct {
}
}
- fn write(self: &File, bytes: []const u8) !void {
+ const WriteError = os.WindowsWriteError || os.PosixWriteError;
+
+ fn write(self: &File, bytes: []const u8) WriteError!void {
if (is_posix) {
try os.posixWrite(self.handle, bytes);
} else if (is_windows) {