authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-27 15:34:46-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-27 15:55:15-04:00
log86bb7e5984c248f37aaa465c7acb0bf97c13b39e
tree8ad3aecb9d378451c3a66914c3b6e0a66ddf1189
parent5de07ab721380c39130a0bd3277a272673e3d644

fixes for windows to build self hosted compiler


7 files changed, 68 insertions(+), 50 deletions(-)

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