mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
windows: Use AccessDenied for ACCESS_DENIED on Windows
Windows defines an `ACCESS_DENIED` error code. There is no PERMISSION_DENIED (or its equivalent) which seems to only exist on POSIX systems. Fix a couple Windows calls code to return `error.AccessDenied` for `ACCESS_DENIED` and to stop mapping AccessDenied into PermissionDenied.
This commit is contained in:
parent
972cab5bb0
commit
f304d8e50a
@ -2447,10 +2447,7 @@ pub const AccessError = posix.AccessError;
|
|||||||
/// open it and handle the error for file not found.
|
/// open it and handle the error for file not found.
|
||||||
pub fn access(self: Dir, sub_path: []const u8, flags: File.OpenFlags) AccessError!void {
|
pub fn access(self: Dir, sub_path: []const u8, flags: File.OpenFlags) AccessError!void {
|
||||||
if (native_os == .windows) {
|
if (native_os == .windows) {
|
||||||
const sub_path_w = windows.sliceToPrefixedFileW(self.fd, sub_path) catch |err| switch (err) {
|
const sub_path_w = try windows.sliceToPrefixedFileW(self.fd, sub_path);
|
||||||
error.AccessDenied => return error.PermissionDenied,
|
|
||||||
else => |e| return e,
|
|
||||||
};
|
|
||||||
return self.accessW(sub_path_w.span().ptr, flags);
|
return self.accessW(sub_path_w.span().ptr, flags);
|
||||||
}
|
}
|
||||||
const path_c = try posix.toPosixPath(sub_path);
|
const path_c = try posix.toPosixPath(sub_path);
|
||||||
@ -2460,10 +2457,7 @@ pub fn access(self: Dir, sub_path: []const u8, flags: File.OpenFlags) AccessErro
|
|||||||
/// Same as `access` except the path parameter is null-terminated.
|
/// Same as `access` except the path parameter is null-terminated.
|
||||||
pub fn accessZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) AccessError!void {
|
pub fn accessZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) AccessError!void {
|
||||||
if (native_os == .windows) {
|
if (native_os == .windows) {
|
||||||
const sub_path_w = windows.cStrToPrefixedFileW(self.fd, sub_path) catch |err| switch (err) {
|
const sub_path_w = try windows.cStrToPrefixedFileW(self.fd, sub_path);
|
||||||
error.AccessDenied => return error.PermissionDenied,
|
|
||||||
else => |e| return e,
|
|
||||||
};
|
|
||||||
return self.accessW(sub_path_w.span().ptr, flags);
|
return self.accessW(sub_path_w.span().ptr, flags);
|
||||||
}
|
}
|
||||||
const os_mode = switch (flags.mode) {
|
const os_mode = switch (flags.mode) {
|
||||||
|
|||||||
@ -1517,7 +1517,7 @@ pub fn GetFileSizeEx(hFile: HANDLE) GetFileSizeError!u64 {
|
|||||||
|
|
||||||
pub const GetFileAttributesError = error{
|
pub const GetFileAttributesError = error{
|
||||||
FileNotFound,
|
FileNotFound,
|
||||||
PermissionDenied,
|
AccessDenied,
|
||||||
Unexpected,
|
Unexpected,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1532,7 +1532,7 @@ pub fn GetFileAttributesW(lpFileName: [*:0]const u16) GetFileAttributesError!DWO
|
|||||||
switch (GetLastError()) {
|
switch (GetLastError()) {
|
||||||
.FILE_NOT_FOUND => return error.FileNotFound,
|
.FILE_NOT_FOUND => return error.FileNotFound,
|
||||||
.PATH_NOT_FOUND => return error.FileNotFound,
|
.PATH_NOT_FOUND => return error.FileNotFound,
|
||||||
.ACCESS_DENIED => return error.PermissionDenied,
|
.ACCESS_DENIED => return error.AccessDenied,
|
||||||
else => |err| return unexpectedError(err),
|
else => |err| return unexpectedError(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1747,12 +1747,12 @@ pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) Ge
|
|||||||
return buf_ptr[0..rc :0];
|
return buf_ptr[0..rc :0];
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const TerminateProcessError = error{ PermissionDenied, Unexpected };
|
pub const TerminateProcessError = error{ AccessDenied, Unexpected };
|
||||||
|
|
||||||
pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) TerminateProcessError!void {
|
pub fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) TerminateProcessError!void {
|
||||||
if (kernel32.TerminateProcess(hProcess, uExitCode) == 0) {
|
if (kernel32.TerminateProcess(hProcess, uExitCode) == 0) {
|
||||||
switch (GetLastError()) {
|
switch (GetLastError()) {
|
||||||
Win32Error.ACCESS_DENIED => return error.PermissionDenied,
|
Win32Error.ACCESS_DENIED => return error.AccessDenied,
|
||||||
else => |err| return unexpectedError(err),
|
else => |err| return unexpectedError(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4896,10 +4896,7 @@ pub const AccessError = error{
|
|||||||
/// Windows. See `fs` for the cross-platform file system API.
|
/// Windows. See `fs` for the cross-platform file system API.
|
||||||
pub fn access(path: []const u8, mode: u32) AccessError!void {
|
pub fn access(path: []const u8, mode: u32) AccessError!void {
|
||||||
if (native_os == .windows) {
|
if (native_os == .windows) {
|
||||||
const path_w = windows.sliceToPrefixedFileW(null, path) catch |err| switch (err) {
|
const path_w = try windows.sliceToPrefixedFileW(null, path);
|
||||||
error.AccessDenied => return error.PermissionDenied,
|
|
||||||
else => |e| return e,
|
|
||||||
};
|
|
||||||
_ = try windows.GetFileAttributesW(path_w.span().ptr);
|
_ = try windows.GetFileAttributesW(path_w.span().ptr);
|
||||||
return;
|
return;
|
||||||
} else if (native_os == .wasi and !builtin.link_libc) {
|
} else if (native_os == .wasi and !builtin.link_libc) {
|
||||||
@ -4912,10 +4909,7 @@ pub fn access(path: []const u8, mode: u32) AccessError!void {
|
|||||||
/// Same as `access` except `path` is null-terminated.
|
/// Same as `access` except `path` is null-terminated.
|
||||||
pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
|
pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
|
||||||
if (native_os == .windows) {
|
if (native_os == .windows) {
|
||||||
const path_w = windows.cStrToPrefixedFileW(null, path) catch |err| switch (err) {
|
const path_w = try windows.cStrToPrefixedFileW(null, path);
|
||||||
error.AccessDenied => return error.PermissionDenied,
|
|
||||||
else => |e| return e,
|
|
||||||
};
|
|
||||||
_ = try windows.GetFileAttributesW(path_w.span().ptr);
|
_ = try windows.GetFileAttributesW(path_w.span().ptr);
|
||||||
return;
|
return;
|
||||||
} else if (native_os == .wasi and !builtin.link_libc) {
|
} else if (native_os == .wasi and !builtin.link_libc) {
|
||||||
|
|||||||
@ -269,7 +269,7 @@ pub fn killWindows(self: *ChildProcess, exit_code: windows.UINT) !Term {
|
|||||||
}
|
}
|
||||||
|
|
||||||
windows.TerminateProcess(self.id, exit_code) catch |err| switch (err) {
|
windows.TerminateProcess(self.id, exit_code) catch |err| switch (err) {
|
||||||
error.PermissionDenied => {
|
error.AccessDenied => {
|
||||||
// Usually when TerminateProcess triggers a ACCESS_DENIED error, it
|
// Usually when TerminateProcess triggers a ACCESS_DENIED error, it
|
||||||
// indicates that the process has already exited, but there may be
|
// indicates that the process has already exited, but there may be
|
||||||
// some rare edge cases where our process handle no longer has the
|
// some rare edge cases where our process handle no longer has the
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user