| author | |
| committer | |
| log | 86bb7e5984c248f37aaa465c7acb0bf97c13b39e |
| tree | 8ad3aecb9d378451c3a66914c3b6e0a66ddf1189 |
| parent | 5de07ab721380c39130a0bd3277a272673e3d644 |
7 files changed, 68 insertions(+), 50 deletions(-)
std/c.zig+2-2| ... | ... | @@ -13,9 +13,9 @@ pub use switch (builtin.os) { |
| 13 | 13 | else => struct {}, |
| 14 | 14 | }; |
| 15 | 15 | |
| 16 | pub fn getErrno(rc: var) u12 { | |
| 16 | pub fn getErrno(rc: var) u16 { | |
| 17 | 17 | if (rc == -1) { |
| 18 | return @intCast(u12, _errno().*); | |
| 18 | return @intCast(u16, _errno().*); | |
| 19 | 19 | } else { |
| 20 | 20 | return 0; |
| 21 | 21 | } |
std/child_process.zig+1-1| ... | ... | @@ -412,7 +412,7 @@ pub const ChildProcess = struct { |
| 412 | 412 | const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore); |
| 413 | 413 | |
| 414 | 414 | const nul_handle = if (any_ignore) blk: { |
| 415 | break :blk try windows.CreateFile("NUL", windows.GENERIC_READ, windows.FILE_SHARE_READ, windows.OPEN_EXISTING, windows.FILE_ATTRIBUTE_NORMAL); | |
| 415 | break :blk try windows.CreateFile("NUL", windows.GENERIC_READ, windows.FILE_SHARE_READ, null, windows.OPEN_EXISTING, windows.FILE_ATTRIBUTE_NORMAL, null); | |
| 416 | 416 | } else blk: { |
| 417 | 417 | break :blk undefined; |
| 418 | 418 | }; |
std/event/fs.zig+29-28| ... | ... | @@ -147,14 +147,14 @@ pub async fn pwriteWindows(loop: *Loop, fd: fd_t, data: []const u8, offset: u64) |
| 147 | 147 | errdefer loop.finishOneEvent(); |
| 148 | 148 | |
| 149 | 149 | errdefer { |
| 150 | _ = windows.CancelIoEx(fd, &resume_node.base.overlapped); | |
| 150 | _ = windows.kernel32.CancelIoEx(fd, &resume_node.base.overlapped); | |
| 151 | 151 | } |
| 152 | 152 | suspend { |
| 153 | _ = windows.WriteFile(fd, data.ptr, @intCast(windows.DWORD, data.len), null, &resume_node.base.overlapped); | |
| 153 | _ = windows.kernel32.WriteFile(fd, data.ptr, @intCast(windows.DWORD, data.len), null, &resume_node.base.overlapped); | |
| 154 | 154 | } |
| 155 | 155 | var bytes_transferred: windows.DWORD = undefined; |
| 156 | if (windows.GetOverlappedResult(fd, &resume_node.base.overlapped, &bytes_transferred, windows.FALSE) == 0) { | |
| 157 | switch (windows.GetLastError()) { | |
| 156 | if (windows.kernel32.GetOverlappedResult(fd, &resume_node.base.overlapped, &bytes_transferred, windows.FALSE) == 0) { | |
| 157 | switch (windows.kernel32.GetLastError()) { | |
| 158 | 158 | windows.ERROR.IO_PENDING => unreachable, |
| 159 | 159 | windows.ERROR.INVALID_USER_BUFFER => return error.SystemResources, |
| 160 | 160 | windows.ERROR.NOT_ENOUGH_MEMORY => return error.SystemResources, |
| ... | ... | @@ -247,7 +247,7 @@ pub async fn preadv(loop: *Loop, fd: fd_t, data: []const []u8, offset: usize) PR |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /// data must outlive the returned promise |
| 250 | pub async fn preadvWindows(loop: *Loop, fd: fd_t, data: []const []u8, offset: u64) os.WindowsReadError!usize { | |
| 250 | pub async fn preadvWindows(loop: *Loop, fd: fd_t, data: []const []u8, offset: u64) !usize { | |
| 251 | 251 | assert(data.len != 0); |
| 252 | 252 | if (data.len == 1) return await (async preadWindows(loop, fd, data[0], offset) catch unreachable); |
| 253 | 253 | |
| ... | ... | @@ -291,19 +291,19 @@ pub async fn preadWindows(loop: *Loop, fd: fd_t, data: []u8, offset: u64) !usize |
| 291 | 291 | }, |
| 292 | 292 | }; |
| 293 | 293 | // TODO only call create io completion port once per fd |
| 294 | _ = windows.CreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined); | |
| 294 | _ = windows.CreateIoCompletionPort(fd, loop.os_data.io_port, undefined, undefined) catch undefined; | |
| 295 | 295 | loop.beginOneEvent(); |
| 296 | 296 | errdefer loop.finishOneEvent(); |
| 297 | 297 | |
| 298 | 298 | errdefer { |
| 299 | _ = windows.CancelIoEx(fd, &resume_node.base.overlapped); | |
| 299 | _ = windows.kernel32.CancelIoEx(fd, &resume_node.base.overlapped); | |
| 300 | 300 | } |
| 301 | 301 | suspend { |
| 302 | _ = windows.ReadFile(fd, data.ptr, @intCast(windows.DWORD, data.len), null, &resume_node.base.overlapped); | |
| 302 | _ = windows.kernel32.ReadFile(fd, data.ptr, @intCast(windows.DWORD, data.len), null, &resume_node.base.overlapped); | |
| 303 | 303 | } |
| 304 | 304 | var bytes_transferred: windows.DWORD = undefined; |
| 305 | if (windows.GetOverlappedResult(fd, &resume_node.base.overlapped, &bytes_transferred, windows.FALSE) == 0) { | |
| 306 | switch (windows.GetLastError()) { | |
| 305 | if (windows.kernel32.GetOverlappedResult(fd, &resume_node.base.overlapped, &bytes_transferred, windows.FALSE) == 0) { | |
| 306 | switch (windows.kernel32.GetLastError()) { | |
| 307 | 307 | windows.ERROR.IO_PENDING => unreachable, |
| 308 | 308 | windows.ERROR.OPERATION_ABORTED => return error.OperationAborted, |
| 309 | 309 | windows.ERROR.BROKEN_PIPE => return error.BrokenPipe, |
| ... | ... | @@ -408,12 +408,14 @@ pub async fn openRead(loop: *Loop, path: []const u8) File.OpenError!fd_t { |
| 408 | 408 | return await (async openPosix(loop, path, flags, File.default_mode) catch unreachable); |
| 409 | 409 | }, |
| 410 | 410 | |
| 411 | builtin.Os.windows => return os.windowsOpen( | |
| 411 | builtin.Os.windows => return windows.CreateFile( | |
| 412 | 412 | path, |
| 413 | 413 | windows.GENERIC_READ, |
| 414 | 414 | windows.FILE_SHARE_READ, |
| 415 | null, | |
| 415 | 416 | windows.OPEN_EXISTING, |
| 416 | 417 | windows.FILE_ATTRIBUTE_NORMAL | windows.FILE_FLAG_OVERLAPPED, |
| 418 | null, | |
| 417 | 419 | ), |
| 418 | 420 | |
| 419 | 421 | else => @compileError("Unsupported OS"), |
| ... | ... | @@ -437,12 +439,14 @@ pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: File.Mode) File. |
| 437 | 439 | const flags = os.O_LARGEFILE | os.O_WRONLY | os.O_CREAT | os.O_CLOEXEC | os.O_TRUNC; |
| 438 | 440 | return await (async openPosix(loop, path, flags, File.default_mode) catch unreachable); |
| 439 | 441 | }, |
| 440 | builtin.Os.windows => return os.windowsOpen( | |
| 442 | builtin.Os.windows => return windows.CreateFile( | |
| 441 | 443 | path, |
| 442 | 444 | windows.GENERIC_WRITE, |
| 443 | 445 | windows.FILE_SHARE_WRITE | windows.FILE_SHARE_READ | windows.FILE_SHARE_DELETE, |
| 446 | null, | |
| 444 | 447 | windows.CREATE_ALWAYS, |
| 445 | 448 | windows.FILE_ATTRIBUTE_NORMAL | windows.FILE_FLAG_OVERLAPPED, |
| 449 | null, | |
| 446 | 450 | ), |
| 447 | 451 | else => @compileError("Unsupported OS"), |
| 448 | 452 | } |
| ... | ... | @@ -460,12 +464,14 @@ pub async fn openReadWrite( |
| 460 | 464 | return await (async openPosix(loop, path, flags, mode) catch unreachable); |
| 461 | 465 | }, |
| 462 | 466 | |
| 463 | builtin.Os.windows => return os.windowsOpen( | |
| 467 | builtin.Os.windows => return windows.CreateFile( | |
| 464 | 468 | path, |
| 465 | 469 | windows.GENERIC_WRITE | windows.GENERIC_READ, |
| 466 | 470 | windows.FILE_SHARE_WRITE | windows.FILE_SHARE_READ | windows.FILE_SHARE_DELETE, |
| 471 | null, | |
| 467 | 472 | windows.OPEN_ALWAYS, |
| 468 | 473 | windows.FILE_ATTRIBUTE_NORMAL | windows.FILE_FLAG_OVERLAPPED, |
| 474 | null, | |
| 469 | 475 | ), |
| 470 | 476 | |
| 471 | 477 | else => @compileError("Unsupported OS"), |
| ... | ... | @@ -622,12 +628,14 @@ pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8, |
| 622 | 628 | } |
| 623 | 629 | |
| 624 | 630 | async fn writeFileWindows(loop: *Loop, path: []const u8, contents: []const u8) !void { |
| 625 | const handle = try os.windowsOpen( | |
| 631 | const handle = try windows.CreateFile( | |
| 626 | 632 | path, |
| 627 | 633 | windows.GENERIC_WRITE, |
| 628 | 634 | windows.FILE_SHARE_WRITE | windows.FILE_SHARE_READ | windows.FILE_SHARE_DELETE, |
| 635 | null, | |
| 629 | 636 | windows.CREATE_ALWAYS, |
| 630 | 637 | windows.FILE_ATTRIBUTE_NORMAL | windows.FILE_FLAG_OVERLAPPED, |
| 638 | null, | |
| 631 | 639 | ); |
| 632 | 640 | defer os.close(handle); |
| 633 | 641 | |
| ... | ... | @@ -1028,7 +1036,7 @@ pub fn Watch(comptime V: type) type { |
| 1028 | 1036 | defer if (!basename_utf16le_null_consumed) self.channel.loop.allocator.free(basename_utf16le_null); |
| 1029 | 1037 | const basename_utf16le_no_null = basename_utf16le_null[0 .. basename_utf16le_null.len - 1]; |
| 1030 | 1038 | |
| 1031 | const dir_handle = windows.CreateFileW( | |
| 1039 | const dir_handle = try windows.CreateFileW( | |
| 1032 | 1040 | dirname_utf16le.ptr, |
| 1033 | 1041 | windows.FILE_LIST_DIRECTORY, |
| 1034 | 1042 | windows.FILE_SHARE_READ | windows.FILE_SHARE_DELETE | windows.FILE_SHARE_WRITE, |
| ... | ... | @@ -1037,15 +1045,8 @@ pub fn Watch(comptime V: type) type { |
| 1037 | 1045 | windows.FILE_FLAG_BACKUP_SEMANTICS | windows.FILE_FLAG_OVERLAPPED, |
| 1038 | 1046 | null, |
| 1039 | 1047 | ); |
| 1040 | if (dir_handle == windows.INVALID_HANDLE_VALUE) { | |
| 1041 | switch (windows.GetLastError()) { | |
| 1042 | windows.ERROR.FILE_NOT_FOUND => return error.FileNotFound, | |
| 1043 | windows.ERROR.PATH_NOT_FOUND => return error.FileNotFound, | |
| 1044 | else => |err| return windows.unexpectedError(err), | |
| 1045 | } | |
| 1046 | } | |
| 1047 | 1048 | var dir_handle_consumed = false; |
| 1048 | defer if (!dir_handle_consumed) os.close(dir_handle); | |
| 1049 | defer if (!dir_handle_consumed) windows.CloseHandle(dir_handle); | |
| 1049 | 1050 | |
| 1050 | 1051 | const held = await (async self.os_data.table_lock.acquire() catch unreachable); |
| 1051 | 1052 | defer held.release(); |
| ... | ... | @@ -1124,7 +1125,7 @@ pub fn Watch(comptime V: type) type { |
| 1124 | 1125 | var event_buf: [4096]u8 align(@alignOf(windows.FILE_NOTIFY_INFORMATION)) = undefined; |
| 1125 | 1126 | |
| 1126 | 1127 | // TODO handle this error not in the channel but in the setup |
| 1127 | _ = os.windowsCreateIoCompletionPort( | |
| 1128 | _ = windows.CreateIoCompletionPort( | |
| 1128 | 1129 | dir_handle, |
| 1129 | 1130 | self.channel.loop.os_data.io_port, |
| 1130 | 1131 | undefined, |
| ... | ... | @@ -1140,10 +1141,10 @@ pub fn Watch(comptime V: type) type { |
| 1140 | 1141 | self.channel.loop.beginOneEvent(); |
| 1141 | 1142 | errdefer self.channel.loop.finishOneEvent(); |
| 1142 | 1143 | errdefer { |
| 1143 | _ = windows.CancelIoEx(dir_handle, &resume_node.base.overlapped); | |
| 1144 | _ = windows.kernel32.CancelIoEx(dir_handle, &resume_node.base.overlapped); | |
| 1144 | 1145 | } |
| 1145 | 1146 | suspend { |
| 1146 | _ = windows.ReadDirectoryChangesW( | |
| 1147 | _ = windows.kernel32.ReadDirectoryChangesW( | |
| 1147 | 1148 | dir_handle, |
| 1148 | 1149 | &event_buf, |
| 1149 | 1150 | @intCast(windows.DWORD, event_buf.len), |
| ... | ... | @@ -1159,8 +1160,8 @@ pub fn Watch(comptime V: type) type { |
| 1159 | 1160 | } |
| 1160 | 1161 | } |
| 1161 | 1162 | var bytes_transferred: windows.DWORD = undefined; |
| 1162 | if (windows.GetOverlappedResult(dir_handle, &resume_node.base.overlapped, &bytes_transferred, windows.FALSE) == 0) { | |
| 1163 | const err = switch (windows.GetLastError()) { | |
| 1163 | if (windows.kernel32.GetOverlappedResult(dir_handle, &resume_node.base.overlapped, &bytes_transferred, windows.FALSE) == 0) { | |
| 1164 | const err = switch (windows.kernel32.GetLastError()) { | |
| 1164 | 1165 | else => |err| windows.unexpectedError(err), |
| 1165 | 1166 | }; |
| 1166 | 1167 | await (async self.channel.put(err) catch unreachable); |
std/fs/file.zig+14-8| ... | ... | @@ -27,7 +27,7 @@ pub const File = struct { |
| 27 | 27 | |
| 28 | 28 | /// Call close to clean up. |
| 29 | 29 | pub fn openRead(path: []const u8) OpenError!File { |
| 30 | if (windows.is_the_target and !builtin.link_libc) { | |
| 30 | if (windows.is_the_target) { | |
| 31 | 31 | const path_w = try windows.sliceToPrefixedFileW(path); |
| 32 | 32 | return openReadW(&path_w); |
| 33 | 33 | } |
| ... | ... | @@ -37,7 +37,7 @@ pub const File = struct { |
| 37 | 37 | |
| 38 | 38 | /// `openRead` except with a null terminated path |
| 39 | 39 | pub fn openReadC(path: [*]const u8) OpenError!File { |
| 40 | if (windows.is_the_target and !builtin.link_libc) { | |
| 40 | if (windows.is_the_target) { | |
| 41 | 41 | const path_w = try windows.cStrToPrefixedFileW(path); |
| 42 | 42 | return openReadW(&path_w); |
| 43 | 43 | } |
| ... | ... | @@ -52,8 +52,10 @@ pub const File = struct { |
| 52 | 52 | path_w, |
| 53 | 53 | windows.GENERIC_READ, |
| 54 | 54 | windows.FILE_SHARE_READ, |
| 55 | null, | |
| 55 | 56 | windows.OPEN_EXISTING, |
| 56 | 57 | windows.FILE_ATTRIBUTE_NORMAL, |
| 58 | null, | |
| 57 | 59 | ); |
| 58 | 60 | return openHandle(handle); |
| 59 | 61 | } |
| ... | ... | @@ -67,7 +69,7 @@ pub const File = struct { |
| 67 | 69 | /// If a file already exists in the destination it will be truncated. |
| 68 | 70 | /// Call close to clean up. |
| 69 | 71 | pub fn openWriteMode(path: []const u8, file_mode: Mode) OpenError!File { |
| 70 | if (windows.is_the_target and !builtin.link_libc) { | |
| 72 | if (windows.is_the_target) { | |
| 71 | 73 | const path_w = try windows.sliceToPrefixedFileW(path); |
| 72 | 74 | return openWriteModeW(&path_w, file_mode); |
| 73 | 75 | } |
| ... | ... | @@ -77,7 +79,7 @@ pub const File = struct { |
| 77 | 79 | |
| 78 | 80 | /// Same as `openWriteMode` except `path` is null-terminated. |
| 79 | 81 | pub fn openWriteModeC(path: [*]const u8, file_mode: Mode) OpenError!File { |
| 80 | if (windows.is_the_target and !builtin.link_libc) { | |
| 82 | if (windows.is_the_target) { | |
| 81 | 83 | const path_w = try windows.cStrToPrefixedFileW(path); |
| 82 | 84 | return openWriteModeW(&path_w, file_mode); |
| 83 | 85 | } |
| ... | ... | @@ -92,8 +94,10 @@ pub const File = struct { |
| 92 | 94 | path_w, |
| 93 | 95 | windows.GENERIC_WRITE, |
| 94 | 96 | windows.FILE_SHARE_WRITE | windows.FILE_SHARE_READ | windows.FILE_SHARE_DELETE, |
| 97 | null, | |
| 95 | 98 | windows.CREATE_ALWAYS, |
| 96 | 99 | windows.FILE_ATTRIBUTE_NORMAL, |
| 100 | null, | |
| 97 | 101 | ); |
| 98 | 102 | return openHandle(handle); |
| 99 | 103 | } |
| ... | ... | @@ -102,7 +106,7 @@ pub const File = struct { |
| 102 | 106 | /// If a file already exists in the destination this returns OpenError.PathAlreadyExists |
| 103 | 107 | /// Call close to clean up. |
| 104 | 108 | pub fn openWriteNoClobber(path: []const u8, file_mode: Mode) OpenError!File { |
| 105 | if (windows.is_the_target and !builtin.link_libc) { | |
| 109 | if (windows.is_the_target) { | |
| 106 | 110 | const path_w = try windows.sliceToPrefixedFileW(path); |
| 107 | 111 | return openWriteNoClobberW(&path_w, file_mode); |
| 108 | 112 | } |
| ... | ... | @@ -111,7 +115,7 @@ pub const File = struct { |
| 111 | 115 | } |
| 112 | 116 | |
| 113 | 117 | pub fn openWriteNoClobberC(path: [*]const u8, file_mode: Mode) OpenError!File { |
| 114 | if (windows.is_the_target and !builtin.link_libc) { | |
| 118 | if (windows.is_the_target) { | |
| 115 | 119 | const path_w = try windows.cStrToPrefixedFileW(path); |
| 116 | 120 | return openWriteNoClobberW(&path_w, file_mode); |
| 117 | 121 | } |
| ... | ... | @@ -125,8 +129,10 @@ pub const File = struct { |
| 125 | 129 | path_w, |
| 126 | 130 | windows.GENERIC_WRITE, |
| 127 | 131 | windows.FILE_SHARE_WRITE | windows.FILE_SHARE_READ | windows.FILE_SHARE_DELETE, |
| 132 | null, | |
| 128 | 133 | windows.CREATE_NEW, |
| 129 | 134 | windows.FILE_ATTRIBUTE_NORMAL, |
| 135 | null, | |
| 130 | 136 | ); |
| 131 | 137 | return openHandle(handle); |
| 132 | 138 | } |
| ... | ... | @@ -198,7 +204,7 @@ pub const File = struct { |
| 198 | 204 | } |
| 199 | 205 | |
| 200 | 206 | pub fn getEndPos(self: File) GetPosError!u64 { |
| 201 | if (windows.is_the_target and !builtin.link_libc) { | |
| 207 | if (windows.is_the_target) { | |
| 202 | 208 | return windows.GetFileSizeEx(self.handle); |
| 203 | 209 | } |
| 204 | 210 | const stat = try os.fstat(self.handle); |
| ... | ... | @@ -208,7 +214,7 @@ pub const File = struct { |
| 208 | 214 | pub const ModeError = os.FStatError; |
| 209 | 215 | |
| 210 | 216 | pub fn mode(self: File) ModeError!Mode { |
| 211 | if (windows.is_the_target and !builtin.link_libc) { | |
| 217 | if (windows.is_the_target) { | |
| 212 | 218 | return {}; |
| 213 | 219 | } |
| 214 | 220 | const stat = try os.fstat(self.handle); |
std/os.zig+9-7| ... | ... | @@ -70,7 +70,7 @@ pub const errno = system.getErrno; |
| 70 | 70 | /// must call `fsync` before `close`. |
| 71 | 71 | /// Note: The Zig standard library does not support POSIX thread cancellation. |
| 72 | 72 | pub fn close(fd: fd_t) void { |
| 73 | if (windows.is_the_target and !builtin.link_libc) { | |
| 73 | if (windows.is_the_target) { | |
| 74 | 74 | return windows.CloseHandle(fd); |
| 75 | 75 | } |
| 76 | 76 | if (wasi.is_the_target) { |
| ... | ... | @@ -236,7 +236,7 @@ pub const ReadError = error{ |
| 236 | 236 | /// This function is for blocking file descriptors only. For non-blocking, see |
| 237 | 237 | /// `readAsync`. |
| 238 | 238 | pub fn read(fd: fd_t, buf: []u8) ReadError!usize { |
| 239 | if (windows.is_the_target and !builtin.link_libc) { | |
| 239 | if (windows.is_the_target) { | |
| 240 | 240 | return windows.ReadFile(fd, buf); |
| 241 | 241 | } |
| 242 | 242 | |
| ... | ... | @@ -363,7 +363,7 @@ pub const WriteError = error{ |
| 363 | 363 | /// This function is for blocking file descriptors only. For non-blocking, see |
| 364 | 364 | /// `writeAsync`. |
| 365 | 365 | pub fn write(fd: fd_t, bytes: []const u8) WriteError!void { |
| 366 | if (windows.is_the_target and !builtin.link_libc) { | |
| 366 | if (windows.is_the_target) { | |
| 367 | 367 | return windows.WriteFile(fd, bytes); |
| 368 | 368 | } |
| 369 | 369 | |
| ... | ... | @@ -1736,7 +1736,7 @@ pub const FStatError = error{ |
| 1736 | 1736 | pub fn fstat(fd: fd_t) FStatError!Stat { |
| 1737 | 1737 | var stat: Stat = undefined; |
| 1738 | 1738 | if (darwin.is_the_target) { |
| 1739 | switch (errno(system.@"fstat$INODE64"(fd, &stat))) { | |
| 1739 | switch (darwin.getErrno(darwin.@"fstat$INODE64"(fd, &stat))) { | |
| 1740 | 1740 | 0 => return stat, |
| 1741 | 1741 | EBADF => unreachable, // Always a race condition. |
| 1742 | 1742 | ENOMEM => return error.SystemResources, |
| ... | ... | @@ -2265,7 +2265,7 @@ pub const RealPathError = error{ |
| 2265 | 2265 | /// The return value is a slice of `out_buffer`, but not necessarily from the beginning. |
| 2266 | 2266 | /// See also `realpathC` and `realpathW`. |
| 2267 | 2267 | pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { |
| 2268 | if (windows.is_the_target and !builtin.link_libc) { | |
| 2268 | if (windows.is_the_target) { | |
| 2269 | 2269 | const pathname_w = try windows.sliceToPrefixedFileW(pathname); |
| 2270 | 2270 | return realpathW(&pathname_w, out_buffer); |
| 2271 | 2271 | } |
| ... | ... | @@ -2275,12 +2275,12 @@ pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathE |
| 2275 | 2275 | |
| 2276 | 2276 | /// Same as `realpath` except `pathname` is null-terminated. |
| 2277 | 2277 | pub fn realpathC(pathname: [*]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { |
| 2278 | if (windows.is_the_target and !builtin.link_libc) { | |
| 2278 | if (windows.is_the_target) { | |
| 2279 | 2279 | const pathname_w = try windows.cStrToPrefixedFileW(pathname); |
| 2280 | 2280 | return realpathW(&pathname_w, out_buffer); |
| 2281 | 2281 | } |
| 2282 | 2282 | if (linux.is_the_target and !builtin.link_libc) { |
| 2283 | const fd = try openC(pathname, O_PATH | O_NONBLOCK | O_CLOEXEC, 0); | |
| 2283 | const fd = try openC(pathname, linux.O_PATH | linux.O_NONBLOCK | linux.O_CLOEXEC, 0); | |
| 2284 | 2284 | defer close(fd); |
| 2285 | 2285 | |
| 2286 | 2286 | var procfs_buf: ["/proc/self/fd/-2147483648\x00".len]u8 = undefined; |
| ... | ... | @@ -2310,8 +2310,10 @@ pub fn realpathW(pathname: [*]const u16, out_buffer: *[MAX_PATH_BYTES]u8) RealPa |
| 2310 | 2310 | pathname, |
| 2311 | 2311 | windows.GENERIC_READ, |
| 2312 | 2312 | windows.FILE_SHARE_READ, |
| 2313 | null, | |
| 2313 | 2314 | windows.OPEN_EXISTING, |
| 2314 | 2315 | windows.FILE_ATTRIBUTE_NORMAL, |
| 2316 | null, | |
| 2315 | 2317 | ); |
| 2316 | 2318 | defer windows.CloseHandle(h_file); |
| 2317 | 2319 |
std/os/bits/windows.zig+7-2| ... | ... | @@ -5,6 +5,8 @@ use @import("../windows/bits.zig"); |
| 5 | 5 | pub const fd_t = HANDLE; |
| 6 | 6 | pub const pid_t = HANDLE; |
| 7 | 7 | |
| 8 | pub const PATH_MAX = 260; | |
| 9 | ||
| 8 | 10 | pub const time_t = c_longlong; |
| 9 | 11 | |
| 10 | 12 | pub const timespec = extern struct { |
| ... | ... | @@ -153,10 +155,13 @@ pub const ETIME = 137; |
| 153 | 155 | pub const ETIMEDOUT = 138; |
| 154 | 156 | pub const ETXTBSY = 139; |
| 155 | 157 | pub const EWOULDBLOCK = 140; |
| 158 | pub const EDQUOT = 10069; | |
| 159 | ||
| 160 | pub const F_OK = 0; | |
| 156 | 161 | |
| 157 | 162 | // These are workarounds for "use of undeclared identifier" compile errors |
| 158 | 163 | // TODO make the compiler even more lazy. don't emit "use of undeclared identifier" errors |
| 159 | 164 | // for if branches that aren't taken. |
| 160 | 165 | pub const SIGKILL = @compileError("Windows libc does not have this"); |
| 161 | pub const EDQUOT = @compileError("Windows libc does not have this"); | |
| 162 | pub const F_OK = 0; | |
| 166 | ||
| 167 |
std/os/windows.zig+6-2| ... | ... | @@ -48,21 +48,25 @@ pub fn CreateFile( |
| 48 | 48 | file_path: []const u8, |
| 49 | 49 | desired_access: DWORD, |
| 50 | 50 | share_mode: DWORD, |
| 51 | lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, | |
| 51 | 52 | creation_disposition: DWORD, |
| 52 | 53 | flags_and_attrs: DWORD, |
| 54 | hTemplateFile: ?HANDLE, | |
| 53 | 55 | ) CreateFileError!HANDLE { |
| 54 | 56 | const file_path_w = try sliceToPrefixedFileW(file_path); |
| 55 | return CreateFileW(&file_path_w, desired_access, share_mode, creation_disposition, flags_and_attrs); | |
| 57 | return CreateFileW(&file_path_w, desired_access, share_mode, lpSecurityAttributes, creation_disposition, flags_and_attrs, hTemplateFile); | |
| 56 | 58 | } |
| 57 | 59 | |
| 58 | 60 | pub fn CreateFileW( |
| 59 | 61 | file_path_w: [*]const u16, |
| 60 | 62 | desired_access: DWORD, |
| 61 | 63 | share_mode: DWORD, |
| 64 | lpSecurityAttributes: ?LPSECURITY_ATTRIBUTES, | |
| 62 | 65 | creation_disposition: DWORD, |
| 63 | 66 | flags_and_attrs: DWORD, |
| 67 | hTemplateFile: ?HANDLE, | |
| 64 | 68 | ) CreateFileError!HANDLE { |
| 65 | const result = kernel32.CreateFileW(file_path_w, desired_access, share_mode, null, creation_disposition, flags_and_attrs, null); | |
| 69 | const result = kernel32.CreateFileW(file_path_w, desired_access, share_mode, lpSecurityAttributes, creation_disposition, flags_and_attrs, hTemplateFile); | |
| 66 | 70 | |
| 67 | 71 | if (result == INVALID_HANDLE_VALUE) { |
| 68 | 72 | switch (kernel32.GetLastError()) { |