authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-30 16:58:32-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-30 16:58:32-05:00
log034ccb4e4e64dda2626535d46a4bc0367bcc1ad2
tree494d551fc7864bbf9f750a24d1f22b593a2ec9db
parent413f9a5cfc9e867e3bc69b47b38c62b52a52d5e9

add missing error code handling on Windows


4 files changed, 9 insertions(+), 2 deletions(-)

lib/std/fs.zig+1
...@@ -841,6 +841,7 @@ pub const Dir = struct {...@@ -841,6 +841,7 @@ pub const Dir = struct {
841 w.STATUS.ACCESS_DENIED => return error.AccessDenied,841 w.STATUS.ACCESS_DENIED => return error.AccessDenied,
842 w.STATUS.PIPE_BUSY => return error.PipeBusy,842 w.STATUS.PIPE_BUSY => return error.PipeBusy,
843 w.STATUS.OBJECT_PATH_SYNTAX_BAD => unreachable,843 w.STATUS.OBJECT_PATH_SYNTAX_BAD => unreachable,
844 w.STATUS.OBJECT_NAME_COLLISION => return error.PathAlreadyExists,
844 else => return w.unexpectedStatus(rc),845 else => return w.unexpectedStatus(rc),
845 }846 }
846 }847 }
lib/std/fs/file.zig+1
...@@ -228,6 +228,7 @@ pub const File = struct {...@@ -228,6 +228,7 @@ pub const File = struct {
228 windows.STATUS.SUCCESS => {},228 windows.STATUS.SUCCESS => {},
229 windows.STATUS.BUFFER_OVERFLOW => {},229 windows.STATUS.BUFFER_OVERFLOW => {},
230 windows.STATUS.INVALID_PARAMETER => unreachable,230 windows.STATUS.INVALID_PARAMETER => unreachable,
231 windows.STATUS.ACCESS_DENIED => return error.AccessDenied,
231 else => return windows.unexpectedStatus(rc),232 else => return windows.unexpectedStatus(rc),
232 }233 }
233 return Stat{234 return Stat{
lib/std/io/test.zig+1-1
...@@ -634,7 +634,7 @@ test "File seek ops" {...@@ -634,7 +634,7 @@ test "File seek ops" {
634634
635test "updateTimes" {635test "updateTimes" {
636 const tmp_file_name = "just_a_temporary_file.txt";636 const tmp_file_name = "just_a_temporary_file.txt";
637 var file = try fs.cwd().createFile(tmp_file_name, .{});637 var file = try fs.cwd().createFile(tmp_file_name, .{ .read = true });
638 defer {638 defer {
639 file.close();639 file.close();
640 std.fs.cwd().deleteFile(tmp_file_name) catch {};640 std.fs.cwd().deleteFile(tmp_file_name) catch {};
lib/std/os.zig+6-1
...@@ -2028,7 +2028,10 @@ pub fn waitpid(pid: i32, flags: u32) u32 {...@@ -2028,7 +2028,10 @@ pub fn waitpid(pid: i32, flags: u32) u32 {
2028 }2028 }
2029}2029}
20302030
2031pub const FStatError = error{SystemResources} || UnexpectedError;2031pub const FStatError = error{
2032 SystemResources,
2033 AccessDenied,
2034} || UnexpectedError;
20322035
2033pub fn fstat(fd: fd_t) FStatError!Stat {2036pub fn fstat(fd: fd_t) FStatError!Stat {
2034 var stat: Stat = undefined;2037 var stat: Stat = undefined;
...@@ -2038,6 +2041,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {...@@ -2038,6 +2041,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
2038 EINVAL => unreachable,2041 EINVAL => unreachable,
2039 EBADF => unreachable, // Always a race condition.2042 EBADF => unreachable, // Always a race condition.
2040 ENOMEM => return error.SystemResources,2043 ENOMEM => return error.SystemResources,
2044 EACCES => return error.AccessDenied,
2041 else => |err| return unexpectedErrno(err),2045 else => |err| return unexpectedErrno(err),
2042 }2046 }
2043 }2047 }
...@@ -2047,6 +2051,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {...@@ -2047,6 +2051,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
2047 EINVAL => unreachable,2051 EINVAL => unreachable,
2048 EBADF => unreachable, // Always a race condition.2052 EBADF => unreachable, // Always a race condition.
2049 ENOMEM => return error.SystemResources,2053 ENOMEM => return error.SystemResources,
2054 EACCES => return error.AccessDenied,
2050 else => |err| return unexpectedErrno(err),2055 else => |err| return unexpectedErrno(err),
2051 }2056 }
2052}2057}