| author | |
| committer | |
| log | 60cd11bd4b48e4dfdf11d1f25cb1ee842a49ee1d |
| tree | 457ea0157f0f42dccf905593426154be8682812b |
| parent | 8591731f2b938b2b55b05181d5ec0e27f79c86fa |
| signature |
It had the downside of running all the comptime blocks and resolving
all the usingnamespaces of each system, when just trying to discover if
the current system is a particular one.
For Darwin, where it's nice to use `std.Target.current.isDarwin()`, this
demonstrates the utility that #425 would provide.26 files changed, 170 insertions(+), 166 deletions(-)
lib/std/build.zig+1-1| ... | ... | @@ -2000,7 +2000,7 @@ pub const RunStep = struct { |
| 2000 | 2000 | } |
| 2001 | 2001 | |
| 2002 | 2002 | pub fn addPathDir(self: *RunStep, search_path: []const u8) void { |
| 2003 | const PATH = if (std.os.windows.is_the_target) "Path" else "PATH"; | |
| 2003 | const PATH = if (builtin.os == .windows) "Path" else "PATH"; | |
| 2004 | 2004 | const env_map = self.getEnvMap(); |
| 2005 | 2005 | const prev_path = env_map.get(PATH) orelse { |
| 2006 | 2006 | env_map.set(PATH, search_path) catch unreachable; |
lib/std/c/darwin.zig+1-1| ... | ... | @@ -36,7 +36,7 @@ const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header; |
| 36 | 36 | /// export a weak symbol here, to be overridden by the real one. |
| 37 | 37 | pub extern "c" var _mh_execute_header: mach_hdr = undefined; |
| 38 | 38 | comptime { |
| 39 | if (std.os.darwin.is_the_target) { | |
| 39 | if (std.Target.current.isDarwin()) { | |
| 40 | 40 | @export("_mh_execute_header", _mh_execute_header, .Weak); |
| 41 | 41 | } |
| 42 | 42 | } |
lib/std/child_process.zig+12-12| ... | ... | @@ -17,9 +17,9 @@ const TailQueue = std.TailQueue; |
| 17 | 17 | const maxInt = std.math.maxInt; |
| 18 | 18 | |
| 19 | 19 | pub const ChildProcess = struct { |
| 20 | pid: if (os.windows.is_the_target) void else i32, | |
| 21 | handle: if (os.windows.is_the_target) windows.HANDLE else void, | |
| 22 | thread_handle: if (os.windows.is_the_target) windows.HANDLE else void, | |
| 20 | pid: if (builtin.os == .windows) void else i32, | |
| 21 | handle: if (builtin.os == .windows) windows.HANDLE else void, | |
| 22 | thread_handle: if (builtin.os == .windows) windows.HANDLE else void, | |
| 23 | 23 | |
| 24 | 24 | allocator: *mem.Allocator, |
| 25 | 25 | |
| ... | ... | @@ -39,16 +39,16 @@ pub const ChildProcess = struct { |
| 39 | 39 | stderr_behavior: StdIo, |
| 40 | 40 | |
| 41 | 41 | /// Set to change the user id when spawning the child process. |
| 42 | uid: if (os.windows.is_the_target) void else ?u32, | |
| 42 | uid: if (builtin.os == .windows) void else ?u32, | |
| 43 | 43 | |
| 44 | 44 | /// Set to change the group id when spawning the child process. |
| 45 | gid: if (os.windows.is_the_target) void else ?u32, | |
| 45 | gid: if (builtin.os == .windows) void else ?u32, | |
| 46 | 46 | |
| 47 | 47 | /// Set to change the current working directory when spawning the child process. |
| 48 | 48 | cwd: ?[]const u8, |
| 49 | 49 | |
| 50 | err_pipe: if (os.windows.is_the_target) void else [2]os.fd_t, | |
| 51 | llnode: if (os.windows.is_the_target) void else TailQueue(*ChildProcess).Node, | |
| 50 | err_pipe: if (builtin.os == .windows) void else [2]os.fd_t, | |
| 51 | llnode: if (builtin.os == .windows) void else TailQueue(*ChildProcess).Node, | |
| 52 | 52 | |
| 53 | 53 | pub const SpawnError = error{OutOfMemory} || os.ExecveError || os.SetIdError || |
| 54 | 54 | os.ChangeCurDirError || windows.CreateProcessError; |
| ... | ... | @@ -82,8 +82,8 @@ pub const ChildProcess = struct { |
| 82 | 82 | .term = null, |
| 83 | 83 | .env_map = null, |
| 84 | 84 | .cwd = null, |
| 85 | .uid = if (os.windows.is_the_target) {} else null, | |
| 86 | .gid = if (os.windows.is_the_target) {} else null, | |
| 85 | .uid = if (builtin.os == .windows) {} else null, | |
| 86 | .gid = if (builtin.os == .windows) {} else null, | |
| 87 | 87 | .stdin = null, |
| 88 | 88 | .stdout = null, |
| 89 | 89 | .stderr = null, |
| ... | ... | @@ -103,7 +103,7 @@ pub const ChildProcess = struct { |
| 103 | 103 | |
| 104 | 104 | /// On success must call `kill` or `wait`. |
| 105 | 105 | pub fn spawn(self: *ChildProcess) !void { |
| 106 | if (os.windows.is_the_target) { | |
| 106 | if (builtin.os == .windows) { | |
| 107 | 107 | return self.spawnWindows(); |
| 108 | 108 | } else { |
| 109 | 109 | return self.spawnPosix(); |
| ... | ... | @@ -117,7 +117,7 @@ pub const ChildProcess = struct { |
| 117 | 117 | |
| 118 | 118 | /// Forcibly terminates child process and then cleans up all resources. |
| 119 | 119 | pub fn kill(self: *ChildProcess) !Term { |
| 120 | if (os.windows.is_the_target) { | |
| 120 | if (builtin.os == .windows) { | |
| 121 | 121 | return self.killWindows(1); |
| 122 | 122 | } else { |
| 123 | 123 | return self.killPosix(); |
| ... | ... | @@ -147,7 +147,7 @@ pub const ChildProcess = struct { |
| 147 | 147 | |
| 148 | 148 | /// Blocks until child process terminates and then cleans up all resources. |
| 149 | 149 | pub fn wait(self: *ChildProcess) !Term { |
| 150 | if (os.windows.is_the_target) { | |
| 150 | if (builtin.os == .windows) { | |
| 151 | 151 | return self.waitWindows(); |
| 152 | 152 | } else { |
| 153 | 153 | return self.waitPosix(); |
lib/std/debug.zig+8-8| ... | ... | @@ -133,7 +133,7 @@ pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void { |
| 133 | 133 | /// chopping off the irrelevant frames and shifting so that the returned addresses pointer |
| 134 | 134 | /// equals the passed in addresses pointer. |
| 135 | 135 | pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace) void { |
| 136 | if (windows.is_the_target) { | |
| 136 | if (builtin.os == .windows) { | |
| 137 | 137 | const addrs = stack_trace.instruction_addresses; |
| 138 | 138 | const u32_addrs_len = @intCast(u32, addrs.len); |
| 139 | 139 | const first_addr = first_address orelse { |
| ... | ... | @@ -310,7 +310,7 @@ pub const StackIterator = struct { |
| 310 | 310 | }; |
| 311 | 311 | |
| 312 | 312 | pub fn writeCurrentStackTrace(out_stream: var, debug_info: *DebugInfo, tty_color: bool, start_addr: ?usize) !void { |
| 313 | if (windows.is_the_target) { | |
| 313 | if (builtin.os == .windows) { | |
| 314 | 314 | return writeCurrentStackTraceWindows(out_stream, debug_info, tty_color, start_addr); |
| 315 | 315 | } |
| 316 | 316 | var it = StackIterator.init(start_addr); |
| ... | ... | @@ -342,10 +342,10 @@ pub fn writeCurrentStackTraceWindows( |
| 342 | 342 | /// TODO once https://github.com/ziglang/zig/issues/3157 is fully implemented, |
| 343 | 343 | /// make this `noasync fn` and remove the individual noasync calls. |
| 344 | 344 | pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void { |
| 345 | if (windows.is_the_target) { | |
| 345 | if (builtin.os == .windows) { | |
| 346 | 346 | return noasync printSourceAtAddressWindows(debug_info, out_stream, address, tty_color); |
| 347 | 347 | } |
| 348 | if (os.darwin.is_the_target) { | |
| 348 | if (comptime std.Target.current.isDarwin()) { | |
| 349 | 349 | return noasync printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color); |
| 350 | 350 | } |
| 351 | 351 | return noasync printSourceAtAddressPosix(debug_info, out_stream, address, tty_color); |
| ... | ... | @@ -832,10 +832,10 @@ pub const OpenSelfDebugInfoError = error{ |
| 832 | 832 | pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo { |
| 833 | 833 | if (builtin.strip_debug_info) |
| 834 | 834 | return error.MissingDebugInfo; |
| 835 | if (windows.is_the_target) { | |
| 835 | if (builtin.os == .windows) { | |
| 836 | 836 | return noasync openSelfDebugInfoWindows(allocator); |
| 837 | 837 | } |
| 838 | if (os.darwin.is_the_target) { | |
| 838 | if (comptime std.Target.current.isDarwin()) { | |
| 839 | 839 | return noasync openSelfDebugInfoMacOs(allocator); |
| 840 | 840 | } |
| 841 | 841 | return noasync openSelfDebugInfoPosix(allocator); |
| ... | ... | @@ -2364,7 +2364,7 @@ pub fn attachSegfaultHandler() void { |
| 2364 | 2364 | if (!have_segfault_handling_support) { |
| 2365 | 2365 | @compileError("segfault handler not supported for this target"); |
| 2366 | 2366 | } |
| 2367 | if (windows.is_the_target) { | |
| 2367 | if (builtin.os == .windows) { | |
| 2368 | 2368 | windows_segfault_handle = windows.kernel32.AddVectoredExceptionHandler(0, handleSegfaultWindows); |
| 2369 | 2369 | return; |
| 2370 | 2370 | } |
| ... | ... | @@ -2378,7 +2378,7 @@ pub fn attachSegfaultHandler() void { |
| 2378 | 2378 | } |
| 2379 | 2379 | |
| 2380 | 2380 | fn resetSegfaultHandler() void { |
| 2381 | if (windows.is_the_target) { | |
| 2381 | if (builtin.os == .windows) { | |
| 2382 | 2382 | if (windows_segfault_handle) |handle| { |
| 2383 | 2383 | assert(windows.kernel32.RemoveVectoredExceptionHandler(handle) != 0); |
| 2384 | 2384 | windows_segfault_handle = null; |
lib/std/event/channel.zig+1-1| ... | ... | @@ -307,7 +307,7 @@ test "std.event.Channel" { |
| 307 | 307 | // https://github.com/ziglang/zig/issues/1908 |
| 308 | 308 | if (builtin.single_threaded) return error.SkipZigTest; |
| 309 | 309 | // https://github.com/ziglang/zig/issues/3251 |
| 310 | if (std.os.freebsd.is_the_target) return error.SkipZigTest; | |
| 310 | if (builtin.os == .freebsd) return error.SkipZigTest; | |
| 311 | 311 | |
| 312 | 312 | var loop: Loop = undefined; |
| 313 | 313 | // TODO make a multi threaded test |
lib/std/event/fs.zig+1-1| ... | ... | @@ -909,7 +909,7 @@ fn hashString(s: []const u16) u32 { |
| 909 | 909 | // var close_op_consumed = false; |
| 910 | 910 | // defer if (!close_op_consumed) close_op.finish(); |
| 911 | 911 | // |
| 912 | // const flags = if (os.darwin.is_the_target) os.O_SYMLINK | os.O_EVTONLY else 0; | |
| 912 | // const flags = if (comptime std.Target.current.isDarwin()) os.O_SYMLINK | os.O_EVTONLY else 0; | |
| 913 | 913 | // const mode = 0; |
| 914 | 914 | // const fd = try await (async openPosix(self.channel.loop, resolved_path, flags, mode) catch unreachable); |
| 915 | 915 | // close_op.setHandle(fd); |
lib/std/event/future.zig+1-1| ... | ... | @@ -86,7 +86,7 @@ test "std.event.Future" { |
| 86 | 86 | // https://github.com/ziglang/zig/issues/1908 |
| 87 | 87 | if (builtin.single_threaded) return error.SkipZigTest; |
| 88 | 88 | // https://github.com/ziglang/zig/issues/3251 |
| 89 | if (std.os.freebsd.is_the_target) return error.SkipZigTest; | |
| 89 | if (builtin.os == .freebsd) return error.SkipZigTest; | |
| 90 | 90 | |
| 91 | 91 | const allocator = std.heap.direct_allocator; |
| 92 | 92 |
lib/std/event/lock.zig+1-1| ... | ... | @@ -119,7 +119,7 @@ test "std.event.Lock" { |
| 119 | 119 | // TODO https://github.com/ziglang/zig/issues/1908 |
| 120 | 120 | if (builtin.single_threaded) return error.SkipZigTest; |
| 121 | 121 | // TODO https://github.com/ziglang/zig/issues/3251 |
| 122 | if (std.os.freebsd.is_the_target) return error.SkipZigTest; | |
| 122 | if (builtin.os == .freebsd) return error.SkipZigTest; | |
| 123 | 123 | |
| 124 | 124 | const allocator = std.heap.direct_allocator; |
| 125 | 125 |
lib/std/fs.zig+9-9| ... | ... | @@ -255,7 +255,7 @@ pub const AtomicFile = struct { |
| 255 | 255 | assert(!self.finished); |
| 256 | 256 | self.file.close(); |
| 257 | 257 | self.finished = true; |
| 258 | if (os.windows.is_the_target) { | |
| 258 | if (builtin.os == .windows) { | |
| 259 | 259 | const dest_path_w = try os.windows.sliceToPrefixedFileW(self.dest_path); |
| 260 | 260 | const tmp_path_w = try os.windows.cStrToPrefixedFileW(&self.tmp_path_buf); |
| 261 | 261 | return os.renameW(&tmp_path_w, &dest_path_w); |
| ... | ... | @@ -659,7 +659,7 @@ pub const Dir = struct { |
| 659 | 659 | /// Closing the returned `Dir` is checked illegal behavior. |
| 660 | 660 | /// On POSIX targets, this function is comptime-callable. |
| 661 | 661 | pub fn cwd() Dir { |
| 662 | if (os.windows.is_the_target) { | |
| 662 | if (builtin.os == .windows) { | |
| 663 | 663 | return Dir{ .fd = os.windows.peb().ProcessParameters.CurrentDirectory.Handle }; |
| 664 | 664 | } else { |
| 665 | 665 | return Dir{ .fd = os.AT_FDCWD }; |
| ... | ... | @@ -711,7 +711,7 @@ pub const Dir = struct { |
| 711 | 711 | |
| 712 | 712 | /// Call `close` on the result when done. |
| 713 | 713 | pub fn openDir(self: Dir, sub_path: []const u8) OpenError!Dir { |
| 714 | if (os.windows.is_the_target) { | |
| 714 | if (builtin.os == .windows) { | |
| 715 | 715 | const sub_path_w = try os.windows.sliceToPrefixedFileW(sub_path); |
| 716 | 716 | return self.openDirW(&sub_path_w); |
| 717 | 717 | } |
| ... | ... | @@ -722,7 +722,7 @@ pub const Dir = struct { |
| 722 | 722 | |
| 723 | 723 | /// Same as `openDir` except the parameter is null-terminated. |
| 724 | 724 | pub fn openDirC(self: Dir, sub_path_c: [*]const u8) OpenError!Dir { |
| 725 | if (os.windows.is_the_target) { | |
| 725 | if (builtin.os == .windows) { | |
| 726 | 726 | const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c); |
| 727 | 727 | return self.openDirW(&sub_path_w); |
| 728 | 728 | } |
| ... | ... | @@ -829,7 +829,7 @@ pub const Dir = struct { |
| 829 | 829 | /// Returns `error.DirNotEmpty` if the directory is not empty. |
| 830 | 830 | /// To delete a directory recursively, see `deleteTree`. |
| 831 | 831 | pub fn deleteDir(self: Dir, sub_path: []const u8) DeleteDirError!void { |
| 832 | if (os.windows.is_the_target) { | |
| 832 | if (builtin.os == .windows) { | |
| 833 | 833 | const sub_path_w = try os.windows.sliceToPrefixedFileW(sub_path); |
| 834 | 834 | return self.deleteDirW(&sub_path_w); |
| 835 | 835 | } |
| ... | ... | @@ -1146,10 +1146,10 @@ pub fn readLinkC(pathname_c: [*]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { |
| 1146 | 1146 | pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfExePathError; |
| 1147 | 1147 | |
| 1148 | 1148 | pub fn openSelfExe() OpenSelfExeError!File { |
| 1149 | if (os.linux.is_the_target) { | |
| 1149 | if (builtin.os == .linux) { | |
| 1150 | 1150 | return File.openReadC(c"/proc/self/exe"); |
| 1151 | 1151 | } |
| 1152 | if (os.windows.is_the_target) { | |
| 1152 | if (builtin.os == .windows) { | |
| 1153 | 1153 | var buf: [os.windows.PATH_MAX_WIDE]u16 = undefined; |
| 1154 | 1154 | const wide_slice = try selfExePathW(&buf); |
| 1155 | 1155 | return File.openReadW(wide_slice.ptr); |
| ... | ... | @@ -1180,7 +1180,7 @@ pub const SelfExePathError = os.ReadLinkError || os.SysCtlError; |
| 1180 | 1180 | /// been deleted, the file path looks something like `/a/b/c/exe (deleted)`. |
| 1181 | 1181 | /// TODO make the return type of this a null terminated pointer |
| 1182 | 1182 | pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 { |
| 1183 | if (os.darwin.is_the_target) { | |
| 1183 | if (comptime std.Target.current.isDarwin()) { | |
| 1184 | 1184 | var u32_len: u32 = out_buffer.len; |
| 1185 | 1185 | const rc = std.c._NSGetExecutablePath(out_buffer, &u32_len); |
| 1186 | 1186 | if (rc != 0) return error.NameTooLong; |
| ... | ... | @@ -1228,7 +1228,7 @@ pub fn selfExeDirPathAlloc(allocator: *Allocator) ![]u8 { |
| 1228 | 1228 | /// Get the directory path that contains the current executable. |
| 1229 | 1229 | /// Returned value is a slice of out_buffer. |
| 1230 | 1230 | pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]const u8 { |
| 1231 | if (os.linux.is_the_target) { | |
| 1231 | if (builtin.os == .linux) { | |
| 1232 | 1232 | // If the currently executing binary has been deleted, |
| 1233 | 1233 | // the file path looks something like `/a/b/c/exe (deleted)` |
| 1234 | 1234 | // This path cannot be opened, but it's valid for determining the directory |
lib/std/fs/file.zig+11-11| ... | ... | @@ -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) { | |
| 30 | if (builtin.os == .windows) { | |
| 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) { | |
| 40 | if (builtin.os == .windows) { | |
| 41 | 41 | const path_w = try windows.cStrToPrefixedFileW(path); |
| 42 | 42 | return openReadW(&path_w); |
| 43 | 43 | } |
| ... | ... | @@ -69,7 +69,7 @@ pub const File = struct { |
| 69 | 69 | /// If a file already exists in the destination it will be truncated. |
| 70 | 70 | /// Call close to clean up. |
| 71 | 71 | pub fn openWriteMode(path: []const u8, file_mode: Mode) OpenError!File { |
| 72 | if (windows.is_the_target) { | |
| 72 | if (builtin.os == .windows) { | |
| 73 | 73 | const path_w = try windows.sliceToPrefixedFileW(path); |
| 74 | 74 | return openWriteModeW(&path_w, file_mode); |
| 75 | 75 | } |
| ... | ... | @@ -79,7 +79,7 @@ pub const File = struct { |
| 79 | 79 | |
| 80 | 80 | /// Same as `openWriteMode` except `path` is null-terminated. |
| 81 | 81 | pub fn openWriteModeC(path: [*]const u8, file_mode: Mode) OpenError!File { |
| 82 | if (windows.is_the_target) { | |
| 82 | if (builtin.os == .windows) { | |
| 83 | 83 | const path_w = try windows.cStrToPrefixedFileW(path); |
| 84 | 84 | return openWriteModeW(&path_w, file_mode); |
| 85 | 85 | } |
| ... | ... | @@ -106,7 +106,7 @@ pub const File = struct { |
| 106 | 106 | /// If a file already exists in the destination this returns OpenError.PathAlreadyExists |
| 107 | 107 | /// Call close to clean up. |
| 108 | 108 | pub fn openWriteNoClobber(path: []const u8, file_mode: Mode) OpenError!File { |
| 109 | if (windows.is_the_target) { | |
| 109 | if (builtin.os == .windows) { | |
| 110 | 110 | const path_w = try windows.sliceToPrefixedFileW(path); |
| 111 | 111 | return openWriteNoClobberW(&path_w, file_mode); |
| 112 | 112 | } |
| ... | ... | @@ -115,7 +115,7 @@ pub const File = struct { |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | pub fn openWriteNoClobberC(path: [*]const u8, file_mode: Mode) OpenError!File { |
| 118 | if (windows.is_the_target) { | |
| 118 | if (builtin.os == .windows) { | |
| 119 | 119 | const path_w = try windows.cStrToPrefixedFileW(path); |
| 120 | 120 | return openWriteNoClobberW(&path_w, file_mode); |
| 121 | 121 | } |
| ... | ... | @@ -174,7 +174,7 @@ pub const File = struct { |
| 174 | 174 | |
| 175 | 175 | /// Test whether ANSI escape codes will be treated as such. |
| 176 | 176 | pub fn supportsAnsiEscapeCodes(self: File) bool { |
| 177 | if (windows.is_the_target) { | |
| 177 | if (builtin.os == .windows) { | |
| 178 | 178 | return os.isCygwinPty(self.handle); |
| 179 | 179 | } |
| 180 | 180 | if (self.isTty()) { |
| ... | ... | @@ -214,7 +214,7 @@ pub const File = struct { |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | pub fn getEndPos(self: File) GetPosError!u64 { |
| 217 | if (windows.is_the_target) { | |
| 217 | if (builtin.os == .windows) { | |
| 218 | 218 | return windows.GetFileSizeEx(self.handle); |
| 219 | 219 | } |
| 220 | 220 | return (try self.stat()).size; |
| ... | ... | @@ -223,7 +223,7 @@ pub const File = struct { |
| 223 | 223 | pub const ModeError = os.FStatError; |
| 224 | 224 | |
| 225 | 225 | pub fn mode(self: File) ModeError!Mode { |
| 226 | if (windows.is_the_target) { | |
| 226 | if (builtin.os == .windows) { | |
| 227 | 227 | return {}; |
| 228 | 228 | } |
| 229 | 229 | return (try self.stat()).mode; |
| ... | ... | @@ -246,7 +246,7 @@ pub const File = struct { |
| 246 | 246 | pub const StatError = os.FStatError; |
| 247 | 247 | |
| 248 | 248 | pub fn stat(self: File) StatError!Stat { |
| 249 | if (windows.is_the_target) { | |
| 249 | if (builtin.os == .windows) { | |
| 250 | 250 | var io_status_block: windows.IO_STATUS_BLOCK = undefined; |
| 251 | 251 | var info: windows.FILE_ALL_INFORMATION = undefined; |
| 252 | 252 | const rc = windows.ntdll.NtQueryInformationFile(self.handle, &io_status_block, &info, @sizeOf(windows.FILE_ALL_INFORMATION), .FileAllInformation); |
| ... | ... | @@ -291,7 +291,7 @@ pub const File = struct { |
| 291 | 291 | /// last modification timestamp in nanoseconds |
| 292 | 292 | mtime: i64, |
| 293 | 293 | ) UpdateTimesError!void { |
| 294 | if (windows.is_the_target) { | |
| 294 | if (builtin.os == .windows) { | |
| 295 | 295 | const atime_ft = windows.nanoSecondsToFileTime(atime); |
| 296 | 296 | const mtime_ft = windows.nanoSecondsToFileTime(mtime); |
| 297 | 297 | return windows.SetFileTime(self.handle, null, &atime_ft, &mtime_ft); |
lib/std/fs/path.zig+17-17| ... | ... | @@ -13,16 +13,16 @@ const process = std.process; |
| 13 | 13 | |
| 14 | 14 | pub const sep_windows = '\\'; |
| 15 | 15 | pub const sep_posix = '/'; |
| 16 | pub const sep = if (windows.is_the_target) sep_windows else sep_posix; | |
| 16 | pub const sep = if (builtin.os == .windows) sep_windows else sep_posix; | |
| 17 | 17 | |
| 18 | 18 | pub const sep_str = [1]u8{sep}; |
| 19 | 19 | |
| 20 | 20 | pub const delimiter_windows = ';'; |
| 21 | 21 | pub const delimiter_posix = ':'; |
| 22 | pub const delimiter = if (windows.is_the_target) delimiter_windows else delimiter_posix; | |
| 22 | pub const delimiter = if (builtin.os == .windows) delimiter_windows else delimiter_posix; | |
| 23 | 23 | |
| 24 | 24 | pub fn isSep(byte: u8) bool { |
| 25 | if (windows.is_the_target) { | |
| 25 | if (builtin.os == .windows) { | |
| 26 | 26 | return byte == '/' or byte == '\\'; |
| 27 | 27 | } else { |
| 28 | 28 | return byte == '/'; |
| ... | ... | @@ -72,7 +72,7 @@ fn joinSep(allocator: *Allocator, separator: u8, paths: []const []const u8) ![]u |
| 72 | 72 | return buf; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | pub const join = if (windows.is_the_target) joinWindows else joinPosix; | |
| 75 | pub const join = if (builtin.os == .windows) joinWindows else joinPosix; | |
| 76 | 76 | |
| 77 | 77 | /// Naively combines a series of paths with the native path seperator. |
| 78 | 78 | /// Allocates memory for the result, which must be freed by the caller. |
| ... | ... | @@ -129,7 +129,7 @@ test "join" { |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | pub fn isAbsolute(path: []const u8) bool { |
| 132 | if (windows.is_the_target) { | |
| 132 | if (builtin.os == .windows) { | |
| 133 | 133 | return isAbsoluteWindows(path); |
| 134 | 134 | } else { |
| 135 | 135 | return isAbsolutePosix(path); |
| ... | ... | @@ -327,7 +327,7 @@ test "windowsParsePath" { |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | pub fn diskDesignator(path: []const u8) []const u8 { |
| 330 | if (windows.is_the_target) { | |
| 330 | if (builtin.os == .windows) { | |
| 331 | 331 | return diskDesignatorWindows(path); |
| 332 | 332 | } else { |
| 333 | 333 | return ""; |
| ... | ... | @@ -392,7 +392,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool { |
| 392 | 392 | |
| 393 | 393 | /// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`. |
| 394 | 394 | pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 { |
| 395 | if (windows.is_the_target) { | |
| 395 | if (builtin.os == .windows) { | |
| 396 | 396 | return resolveWindows(allocator, paths); |
| 397 | 397 | } else { |
| 398 | 398 | return resolvePosix(allocator, paths); |
| ... | ... | @@ -409,7 +409,7 @@ pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 { |
| 409 | 409 | /// Without performing actual syscalls, resolving `..` could be incorrect. |
| 410 | 410 | pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 { |
| 411 | 411 | if (paths.len == 0) { |
| 412 | assert(windows.is_the_target); // resolveWindows called on non windows can't use getCwd | |
| 412 | assert(builtin.os == .windows); // resolveWindows called on non windows can't use getCwd | |
| 413 | 413 | return process.getCwdAlloc(allocator); |
| 414 | 414 | } |
| 415 | 415 | |
| ... | ... | @@ -504,7 +504,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 { |
| 504 | 504 | result_disk_designator = result[0..result_index]; |
| 505 | 505 | }, |
| 506 | 506 | WindowsPath.Kind.None => { |
| 507 | assert(windows.is_the_target); // resolveWindows called on non windows can't use getCwd | |
| 507 | assert(builtin.os == .windows); // resolveWindows called on non windows can't use getCwd | |
| 508 | 508 | const cwd = try process.getCwdAlloc(allocator); |
| 509 | 509 | defer allocator.free(cwd); |
| 510 | 510 | const parsed_cwd = windowsParsePath(cwd); |
| ... | ... | @@ -519,7 +519,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 { |
| 519 | 519 | }, |
| 520 | 520 | } |
| 521 | 521 | } else { |
| 522 | assert(windows.is_the_target); // resolveWindows called on non windows can't use getCwd | |
| 522 | assert(builtin.os == .windows); // resolveWindows called on non windows can't use getCwd | |
| 523 | 523 | // TODO call get cwd for the result_disk_designator instead of the global one |
| 524 | 524 | const cwd = try process.getCwdAlloc(allocator); |
| 525 | 525 | defer allocator.free(cwd); |
| ... | ... | @@ -590,7 +590,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 { |
| 590 | 590 | /// Without performing actual syscalls, resolving `..` could be incorrect. |
| 591 | 591 | pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 { |
| 592 | 592 | if (paths.len == 0) { |
| 593 | assert(!windows.is_the_target); // resolvePosix called on windows can't use getCwd | |
| 593 | assert(builtin.os != .windows); // resolvePosix called on windows can't use getCwd | |
| 594 | 594 | return process.getCwdAlloc(allocator); |
| 595 | 595 | } |
| 596 | 596 | |
| ... | ... | @@ -612,7 +612,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 { |
| 612 | 612 | if (have_abs) { |
| 613 | 613 | result = try allocator.alloc(u8, max_size); |
| 614 | 614 | } else { |
| 615 | assert(!windows.is_the_target); // resolvePosix called on windows can't use getCwd | |
| 615 | assert(builtin.os != .windows); // resolvePosix called on windows can't use getCwd | |
| 616 | 616 | const cwd = try process.getCwdAlloc(allocator); |
| 617 | 617 | defer allocator.free(cwd); |
| 618 | 618 | result = try allocator.alloc(u8, max_size + cwd.len + 1); |
| ... | ... | @@ -653,7 +653,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 { |
| 653 | 653 | |
| 654 | 654 | test "resolve" { |
| 655 | 655 | const cwd = try process.getCwdAlloc(debug.global_allocator); |
| 656 | if (windows.is_the_target) { | |
| 656 | if (builtin.os == .windows) { | |
| 657 | 657 | if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) { |
| 658 | 658 | cwd[0] = asciiUpper(cwd[0]); |
| 659 | 659 | } |
| ... | ... | @@ -669,7 +669,7 @@ test "resolveWindows" { |
| 669 | 669 | // TODO https://github.com/ziglang/zig/issues/3288 |
| 670 | 670 | return error.SkipZigTest; |
| 671 | 671 | } |
| 672 | if (windows.is_the_target) { | |
| 672 | if (builtin.os == .windows) { | |
| 673 | 673 | const cwd = try process.getCwdAlloc(debug.global_allocator); |
| 674 | 674 | const parsed_cwd = windowsParsePath(cwd); |
| 675 | 675 | { |
| ... | ... | @@ -735,7 +735,7 @@ fn testResolvePosix(paths: []const []const u8) []u8 { |
| 735 | 735 | /// If the path is a file in the current directory (no directory component) |
| 736 | 736 | /// then returns null |
| 737 | 737 | pub fn dirname(path: []const u8) ?[]const u8 { |
| 738 | if (windows.is_the_target) { | |
| 738 | if (builtin.os == .windows) { | |
| 739 | 739 | return dirnameWindows(path); |
| 740 | 740 | } else { |
| 741 | 741 | return dirnamePosix(path); |
| ... | ... | @@ -867,7 +867,7 @@ fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) void { |
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | pub fn basename(path: []const u8) []const u8 { |
| 870 | if (windows.is_the_target) { | |
| 870 | if (builtin.os == .windows) { | |
| 871 | 871 | return basenameWindows(path); |
| 872 | 872 | } else { |
| 873 | 873 | return basenamePosix(path); |
| ... | ... | @@ -983,7 +983,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) void { |
| 983 | 983 | /// string is returned. |
| 984 | 984 | /// On Windows this canonicalizes the drive to a capital letter and paths to `\\`. |
| 985 | 985 | pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 { |
| 986 | if (windows.is_the_target) { | |
| 986 | if (builtin.os == .windows) { | |
| 987 | 987 | return relativeWindows(allocator, from, to); |
| 988 | 988 | } else { |
| 989 | 989 | return relativePosix(allocator, from, to); |
lib/std/heap.zig+3-3| ... | ... | @@ -44,7 +44,7 @@ const DirectAllocator = struct { |
| 44 | 44 | if (n == 0) |
| 45 | 45 | return (([*]u8)(undefined))[0..0]; |
| 46 | 46 | |
| 47 | if (os.windows.is_the_target) { | |
| 47 | if (builtin.os == .windows) { | |
| 48 | 48 | const w = os.windows; |
| 49 | 49 | |
| 50 | 50 | // Although officially it's at least aligned to page boundary, |
| ... | ... | @@ -130,7 +130,7 @@ const DirectAllocator = struct { |
| 130 | 130 | |
| 131 | 131 | fn shrink(allocator: *Allocator, old_mem_unaligned: []u8, old_align: u29, new_size: usize, new_align: u29) []u8 { |
| 132 | 132 | const old_mem = @alignCast(mem.page_size, old_mem_unaligned); |
| 133 | if (os.windows.is_the_target) { | |
| 133 | if (builtin.os == .windows) { | |
| 134 | 134 | const w = os.windows; |
| 135 | 135 | if (new_size == 0) { |
| 136 | 136 | // From the docs: |
| ... | ... | @@ -170,7 +170,7 @@ const DirectAllocator = struct { |
| 170 | 170 | |
| 171 | 171 | fn realloc(allocator: *Allocator, old_mem_unaligned: []u8, old_align: u29, new_size: usize, new_align: u29) ![]u8 { |
| 172 | 172 | const old_mem = @alignCast(mem.page_size, old_mem_unaligned); |
| 173 | if (os.windows.is_the_target) { | |
| 173 | if (builtin.os == .windows) { | |
| 174 | 174 | if (old_mem.len == 0) { |
| 175 | 175 | return alloc(allocator, new_size, new_align); |
| 176 | 176 | } |
lib/std/io.zig+3-3| ... | ... | @@ -37,7 +37,7 @@ pub const is_async = mode != .blocking; |
| 37 | 37 | pub const GetStdIoError = os.windows.GetStdHandleError; |
| 38 | 38 | |
| 39 | 39 | pub fn getStdOut() GetStdIoError!File { |
| 40 | if (os.windows.is_the_target) { | |
| 40 | if (builtin.os == .windows) { | |
| 41 | 41 | const handle = try os.windows.GetStdHandle(os.windows.STD_OUTPUT_HANDLE); |
| 42 | 42 | return File.openHandle(handle); |
| 43 | 43 | } |
| ... | ... | @@ -45,7 +45,7 @@ pub fn getStdOut() GetStdIoError!File { |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | pub fn getStdErr() GetStdIoError!File { |
| 48 | if (os.windows.is_the_target) { | |
| 48 | if (builtin.os == .windows) { | |
| 49 | 49 | const handle = try os.windows.GetStdHandle(os.windows.STD_ERROR_HANDLE); |
| 50 | 50 | return File.openHandle(handle); |
| 51 | 51 | } |
| ... | ... | @@ -53,7 +53,7 @@ pub fn getStdErr() GetStdIoError!File { |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | pub fn getStdIn() GetStdIoError!File { |
| 56 | if (os.windows.is_the_target) { | |
| 56 | if (builtin.os == .windows) { | |
| 57 | 57 | const handle = try os.windows.GetStdHandle(os.windows.STD_INPUT_HANDLE); |
| 58 | 58 | return File.openHandle(handle); |
| 59 | 59 | } |
lib/std/os.zig+64-61| ... | ... | @@ -85,13 +85,13 @@ pub const errno = system.getErrno; |
| 85 | 85 | /// must call `fsync` before `close`. |
| 86 | 86 | /// Note: The Zig standard library does not support POSIX thread cancellation. |
| 87 | 87 | pub fn close(fd: fd_t) void { |
| 88 | if (windows.is_the_target) { | |
| 88 | if (builtin.os == .windows) { | |
| 89 | 89 | return windows.CloseHandle(fd); |
| 90 | 90 | } |
| 91 | if (wasi.is_the_target) { | |
| 91 | if (builtin.os == .wasi) { | |
| 92 | 92 | _ = wasi.fd_close(fd); |
| 93 | 93 | } |
| 94 | if (darwin.is_the_target) { | |
| 94 | if (comptime std.Target.current.isDarwin()) { | |
| 95 | 95 | // This avoids the EINTR problem. |
| 96 | 96 | switch (darwin.getErrno(darwin.@"close$NOCANCEL"(fd))) { |
| 97 | 97 | EBADF => unreachable, // Always a race condition. |
| ... | ... | @@ -113,12 +113,12 @@ pub const GetRandomError = OpenError; |
| 113 | 113 | /// appropriate OS-specific library call. Otherwise it uses the zig standard |
| 114 | 114 | /// library implementation. |
| 115 | 115 | pub fn getrandom(buffer: []u8) GetRandomError!void { |
| 116 | if (windows.is_the_target) { | |
| 116 | if (builtin.os == .windows) { | |
| 117 | 117 | return windows.RtlGenRandom(buffer); |
| 118 | 118 | } |
| 119 | if (linux.is_the_target or freebsd.is_the_target) { | |
| 119 | if (builtin.os == .linux or builtin.os == .freebsd) { | |
| 120 | 120 | var buf = buffer; |
| 121 | const use_c = !linux.is_the_target or | |
| 121 | const use_c = builtin.os != .linux or | |
| 122 | 122 | std.c.versionCheck(builtin.Version{ .major = 2, .minor = 25, .patch = 0 }).ok; |
| 123 | 123 | |
| 124 | 124 | while (buf.len != 0) { |
| ... | ... | @@ -145,7 +145,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void { |
| 145 | 145 | } |
| 146 | 146 | return; |
| 147 | 147 | } |
| 148 | if (wasi.is_the_target) { | |
| 148 | if (builtin.os == .wasi) { | |
| 149 | 149 | switch (wasi.random_get(buffer.ptr, buffer.len)) { |
| 150 | 150 | 0 => return, |
| 151 | 151 | else => |err| return unexpectedErrno(err), |
| ... | ... | @@ -175,7 +175,7 @@ pub fn abort() noreturn { |
| 175 | 175 | // MSVCRT abort() sometimes opens a popup window which is undesirable, so |
| 176 | 176 | // even when linking libc on Windows we use our own abort implementation. |
| 177 | 177 | // See https://github.com/ziglang/zig/issues/2071 for more details. |
| 178 | if (windows.is_the_target) { | |
| 178 | if (builtin.os == .windows) { | |
| 179 | 179 | if (builtin.mode == .Debug) { |
| 180 | 180 | @breakpoint(); |
| 181 | 181 | } |
| ... | ... | @@ -206,14 +206,14 @@ pub fn raise(sig: u8) RaiseError!void { |
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | if (wasi.is_the_target) { | |
| 209 | if (builtin.os == .wasi) { | |
| 210 | 210 | switch (wasi.proc_raise(SIGABRT)) { |
| 211 | 211 | 0 => return, |
| 212 | 212 | else => |err| return unexpectedErrno(err), |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | if (linux.is_the_target) { | |
| 216 | if (builtin.os == .linux) { | |
| 217 | 217 | var set: linux.sigset_t = undefined; |
| 218 | 218 | linux.blockAppSignals(&set); |
| 219 | 219 | const tid = linux.syscall0(linux.SYS_gettid); |
| ... | ... | @@ -245,16 +245,16 @@ pub fn exit(status: u8) noreturn { |
| 245 | 245 | if (builtin.link_libc) { |
| 246 | 246 | system.exit(status); |
| 247 | 247 | } |
| 248 | if (windows.is_the_target) { | |
| 248 | if (builtin.os == .windows) { | |
| 249 | 249 | windows.kernel32.ExitProcess(status); |
| 250 | 250 | } |
| 251 | if (wasi.is_the_target) { | |
| 251 | if (builtin.os == .wasi) { | |
| 252 | 252 | wasi.proc_exit(status); |
| 253 | 253 | } |
| 254 | if (linux.is_the_target and !builtin.single_threaded) { | |
| 254 | if (builtin.os == .linux and !builtin.single_threaded) { | |
| 255 | 255 | linux.exit_group(status); |
| 256 | 256 | } |
| 257 | if (uefi.is_the_target) { | |
| 257 | if (builtin.os == .uefi) { | |
| 258 | 258 | // exit() is only avaliable if exitBootServices() has not been called yet. |
| 259 | 259 | // This call to exit should not fail, so we don't care about its return value. |
| 260 | 260 | if (uefi.system_table.boot_services) |bs| { |
| ... | ... | @@ -283,11 +283,11 @@ pub const ReadError = error{ |
| 283 | 283 | /// If the application has a global event loop enabled, EAGAIN is handled |
| 284 | 284 | /// via the event loop. Otherwise EAGAIN results in error.WouldBlock. |
| 285 | 285 | pub fn read(fd: fd_t, buf: []u8) ReadError!usize { |
| 286 | if (windows.is_the_target) { | |
| 286 | if (builtin.os == .windows) { | |
| 287 | 287 | return windows.ReadFile(fd, buf); |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | if (wasi.is_the_target and !builtin.link_libc) { | |
| 290 | if (builtin.os == .wasi and !builtin.link_libc) { | |
| 291 | 291 | const iovs = [1]iovec{iovec{ |
| 292 | 292 | .iov_base = buf.ptr, |
| 293 | 293 | .iov_len = buf.len, |
| ... | ... | @@ -327,7 +327,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize { |
| 327 | 327 | /// Number of bytes read is returned. Upon reading end-of-file, zero is returned. |
| 328 | 328 | /// This function is for blocking file descriptors only. |
| 329 | 329 | pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) ReadError!usize { |
| 330 | if (darwin.is_the_target) { | |
| 330 | if (comptime std.Target.current.isDarwin()) { | |
| 331 | 331 | // Darwin does not have preadv but it does have pread. |
| 332 | 332 | var off: usize = 0; |
| 333 | 333 | var iov_i: usize = 0; |
| ... | ... | @@ -398,11 +398,11 @@ pub const WriteError = error{ |
| 398 | 398 | /// Write to a file descriptor. Keeps trying if it gets interrupted. |
| 399 | 399 | /// This function is for blocking file descriptors only. |
| 400 | 400 | pub fn write(fd: fd_t, bytes: []const u8) WriteError!void { |
| 401 | if (windows.is_the_target) { | |
| 401 | if (builtin.os == .windows) { | |
| 402 | 402 | return windows.WriteFile(fd, bytes); |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | if (wasi.is_the_target and !builtin.link_libc) { | |
| 405 | if (builtin.os == .wasi and !builtin.link_libc) { | |
| 406 | 406 | const ciovs = [1]iovec_const{iovec_const{ |
| 407 | 407 | .iov_base = bytes.ptr, |
| 408 | 408 | .iov_len = bytes.len, |
| ... | ... | @@ -477,7 +477,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!void { |
| 477 | 477 | /// This function is for blocking file descriptors only. For non-blocking, see |
| 478 | 478 | /// `pwritevAsync`. |
| 479 | 479 | pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) WriteError!void { |
| 480 | if (darwin.is_the_target) { | |
| 480 | if (comptime std.Target.current.isDarwin()) { | |
| 481 | 481 | // Darwin does not have pwritev but it does have pwrite. |
| 482 | 482 | var off: usize = 0; |
| 483 | 483 | var iov_i: usize = 0; |
| ... | ... | @@ -841,7 +841,7 @@ pub const GetCwdError = error{ |
| 841 | 841 | |
| 842 | 842 | /// The result is a slice of out_buffer, indexed from 0. |
| 843 | 843 | pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { |
| 844 | if (windows.is_the_target) { | |
| 844 | if (builtin.os == .windows) { | |
| 845 | 845 | return windows.GetCurrentDirectory(out_buffer); |
| 846 | 846 | } |
| 847 | 847 | |
| ... | ... | @@ -882,7 +882,7 @@ pub const SymLinkError = error{ |
| 882 | 882 | /// If `sym_link_path` exists, it will not be overwritten. |
| 883 | 883 | /// See also `symlinkC` and `symlinkW`. |
| 884 | 884 | pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError!void { |
| 885 | if (windows.is_the_target) { | |
| 885 | if (builtin.os == .windows) { | |
| 886 | 886 | const target_path_w = try windows.sliceToPrefixedFileW(target_path); |
| 887 | 887 | const sym_link_path_w = try windows.sliceToPrefixedFileW(sym_link_path); |
| 888 | 888 | return windows.CreateSymbolicLinkW(&sym_link_path_w, &target_path_w, 0); |
| ... | ... | @@ -896,7 +896,7 @@ pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError! |
| 896 | 896 | /// This is the same as `symlink` except the parameters are null-terminated pointers. |
| 897 | 897 | /// See also `symlink`. |
| 898 | 898 | pub fn symlinkC(target_path: [*]const u8, sym_link_path: [*]const u8) SymLinkError!void { |
| 899 | if (windows.is_the_target) { | |
| 899 | if (builtin.os == .windows) { | |
| 900 | 900 | const target_path_w = try windows.cStrToPrefixedFileW(target_path); |
| 901 | 901 | const sym_link_path_w = try windows.cStrToPrefixedFileW(sym_link_path); |
| 902 | 902 | return windows.CreateSymbolicLinkW(&sym_link_path_w, &target_path_w, 0); |
| ... | ... | @@ -971,7 +971,7 @@ pub const UnlinkError = error{ |
| 971 | 971 | /// Delete a name and possibly the file it refers to. |
| 972 | 972 | /// See also `unlinkC`. |
| 973 | 973 | pub fn unlink(file_path: []const u8) UnlinkError!void { |
| 974 | if (windows.is_the_target) { | |
| 974 | if (builtin.os == .windows) { | |
| 975 | 975 | const file_path_w = try windows.sliceToPrefixedFileW(file_path); |
| 976 | 976 | return windows.DeleteFileW(&file_path_w); |
| 977 | 977 | } else { |
| ... | ... | @@ -982,7 +982,7 @@ pub fn unlink(file_path: []const u8) UnlinkError!void { |
| 982 | 982 | |
| 983 | 983 | /// Same as `unlink` except the parameter is a null terminated UTF8-encoded string. |
| 984 | 984 | pub fn unlinkC(file_path: [*]const u8) UnlinkError!void { |
| 985 | if (windows.is_the_target) { | |
| 985 | if (builtin.os == .windows) { | |
| 986 | 986 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 987 | 987 | return windows.DeleteFileW(&file_path_w); |
| 988 | 988 | } |
| ... | ... | @@ -1012,7 +1012,7 @@ pub const UnlinkatError = UnlinkError || error{ |
| 1012 | 1012 | |
| 1013 | 1013 | /// Delete a file name and possibly the file it refers to, based on an open directory handle. |
| 1014 | 1014 | pub fn unlinkat(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!void { |
| 1015 | if (windows.is_the_target) { | |
| 1015 | if (builtin.os == .windows) { | |
| 1016 | 1016 | const file_path_w = try windows.sliceToPrefixedFileW(file_path); |
| 1017 | 1017 | return unlinkatW(dirfd, &file_path_w, flags); |
| 1018 | 1018 | } |
| ... | ... | @@ -1022,7 +1022,7 @@ pub fn unlinkat(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!vo |
| 1022 | 1022 | |
| 1023 | 1023 | /// Same as `unlinkat` but `file_path` is a null-terminated string. |
| 1024 | 1024 | pub fn unlinkatC(dirfd: fd_t, file_path_c: [*]const u8, flags: u32) UnlinkatError!void { |
| 1025 | if (windows.is_the_target) { | |
| 1025 | if (builtin.os == .windows) { | |
| 1026 | 1026 | const file_path_w = try windows.cStrToPrefixedFileW(file_path_c); |
| 1027 | 1027 | return unlinkatW(dirfd, &file_path_w, flags); |
| 1028 | 1028 | } |
| ... | ... | @@ -1133,7 +1133,7 @@ const RenameError = error{ |
| 1133 | 1133 | |
| 1134 | 1134 | /// Change the name or location of a file. |
| 1135 | 1135 | pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void { |
| 1136 | if (windows.is_the_target) { | |
| 1136 | if (builtin.os == .windows) { | |
| 1137 | 1137 | const old_path_w = try windows.sliceToPrefixedFileW(old_path); |
| 1138 | 1138 | const new_path_w = try windows.sliceToPrefixedFileW(new_path); |
| 1139 | 1139 | return renameW(&old_path_w, &new_path_w); |
| ... | ... | @@ -1146,7 +1146,7 @@ pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void { |
| 1146 | 1146 | |
| 1147 | 1147 | /// Same as `rename` except the parameters are null-terminated byte arrays. |
| 1148 | 1148 | pub fn renameC(old_path: [*]const u8, new_path: [*]const u8) RenameError!void { |
| 1149 | if (windows.is_the_target) { | |
| 1149 | if (builtin.os == .windows) { | |
| 1150 | 1150 | const old_path_w = try windows.cStrToPrefixedFileW(old_path); |
| 1151 | 1151 | const new_path_w = try windows.cStrToPrefixedFileW(new_path); |
| 1152 | 1152 | return renameW(&old_path_w, &new_path_w); |
| ... | ... | @@ -1201,7 +1201,7 @@ pub const MakeDirError = error{ |
| 1201 | 1201 | /// Create a directory. |
| 1202 | 1202 | /// `mode` is ignored on Windows. |
| 1203 | 1203 | pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void { |
| 1204 | if (windows.is_the_target) { | |
| 1204 | if (builtin.os == .windows) { | |
| 1205 | 1205 | const dir_path_w = try windows.sliceToPrefixedFileW(dir_path); |
| 1206 | 1206 | return windows.CreateDirectoryW(&dir_path_w, null); |
| 1207 | 1207 | } else { |
| ... | ... | @@ -1212,7 +1212,7 @@ pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void { |
| 1212 | 1212 | |
| 1213 | 1213 | /// Same as `mkdir` but the parameter is a null-terminated UTF8-encoded string. |
| 1214 | 1214 | pub fn mkdirC(dir_path: [*]const u8, mode: u32) MakeDirError!void { |
| 1215 | if (windows.is_the_target) { | |
| 1215 | if (builtin.os == .windows) { | |
| 1216 | 1216 | const dir_path_w = try windows.cStrToPrefixedFileW(dir_path); |
| 1217 | 1217 | return windows.CreateDirectoryW(&dir_path_w, null); |
| 1218 | 1218 | } |
| ... | ... | @@ -1251,7 +1251,7 @@ pub const DeleteDirError = error{ |
| 1251 | 1251 | |
| 1252 | 1252 | /// Deletes an empty directory. |
| 1253 | 1253 | pub fn rmdir(dir_path: []const u8) DeleteDirError!void { |
| 1254 | if (windows.is_the_target) { | |
| 1254 | if (builtin.os == .windows) { | |
| 1255 | 1255 | const dir_path_w = try windows.sliceToPrefixedFileW(dir_path); |
| 1256 | 1256 | return windows.RemoveDirectoryW(&dir_path_w); |
| 1257 | 1257 | } else { |
| ... | ... | @@ -1262,7 +1262,7 @@ pub fn rmdir(dir_path: []const u8) DeleteDirError!void { |
| 1262 | 1262 | |
| 1263 | 1263 | /// Same as `rmdir` except the parameter is null-terminated. |
| 1264 | 1264 | pub fn rmdirC(dir_path: [*]const u8) DeleteDirError!void { |
| 1265 | if (windows.is_the_target) { | |
| 1265 | if (builtin.os == .windows) { | |
| 1266 | 1266 | const dir_path_w = try windows.cStrToPrefixedFileW(dir_path); |
| 1267 | 1267 | return windows.RemoveDirectoryW(&dir_path_w); |
| 1268 | 1268 | } |
| ... | ... | @@ -1298,7 +1298,7 @@ pub const ChangeCurDirError = error{ |
| 1298 | 1298 | /// Changes the current working directory of the calling process. |
| 1299 | 1299 | /// `dir_path` is recommended to be a UTF-8 encoded string. |
| 1300 | 1300 | pub fn chdir(dir_path: []const u8) ChangeCurDirError!void { |
| 1301 | if (windows.is_the_target) { | |
| 1301 | if (builtin.os == .windows) { | |
| 1302 | 1302 | const dir_path_w = try windows.sliceToPrefixedFileW(dir_path); |
| 1303 | 1303 | @compileError("TODO implement chdir for Windows"); |
| 1304 | 1304 | } else { |
| ... | ... | @@ -1309,7 +1309,7 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void { |
| 1309 | 1309 | |
| 1310 | 1310 | /// Same as `chdir` except the parameter is null-terminated. |
| 1311 | 1311 | pub fn chdirC(dir_path: [*]const u8) ChangeCurDirError!void { |
| 1312 | if (windows.is_the_target) { | |
| 1312 | if (builtin.os == .windows) { | |
| 1313 | 1313 | const dir_path_w = try windows.cStrToPrefixedFileW(dir_path); |
| 1314 | 1314 | @compileError("TODO implement chdir for Windows"); |
| 1315 | 1315 | } |
| ... | ... | @@ -1340,7 +1340,7 @@ pub const ReadLinkError = error{ |
| 1340 | 1340 | /// Read value of a symbolic link. |
| 1341 | 1341 | /// The return value is a slice of `out_buffer` from index 0. |
| 1342 | 1342 | pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 1343 | if (windows.is_the_target) { | |
| 1343 | if (builtin.os == .windows) { | |
| 1344 | 1344 | const file_path_w = try windows.sliceToPrefixedFileW(file_path); |
| 1345 | 1345 | @compileError("TODO implement readlink for Windows"); |
| 1346 | 1346 | } else { |
| ... | ... | @@ -1351,7 +1351,7 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 1351 | 1351 | |
| 1352 | 1352 | /// Same as `readlink` except `file_path` is null-terminated. |
| 1353 | 1353 | pub fn readlinkC(file_path: [*]const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 1354 | if (windows.is_the_target) { | |
| 1354 | if (builtin.os == .windows) { | |
| 1355 | 1355 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 1356 | 1356 | @compileError("TODO implement readlink for Windows"); |
| 1357 | 1357 | } |
| ... | ... | @@ -1372,7 +1372,7 @@ pub fn readlinkC(file_path: [*]const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | 1374 | pub fn readlinkatC(dirfd: fd_t, file_path: [*]const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 1375 | if (windows.is_the_target) { | |
| 1375 | if (builtin.os == .windows) { | |
| 1376 | 1376 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 1377 | 1377 | @compileError("TODO implement readlink for Windows"); |
| 1378 | 1378 | } |
| ... | ... | @@ -1440,7 +1440,7 @@ pub fn setregid(rgid: u32, egid: u32) SetIdError!void { |
| 1440 | 1440 | |
| 1441 | 1441 | /// Test whether a file descriptor refers to a terminal. |
| 1442 | 1442 | pub fn isatty(handle: fd_t) bool { |
| 1443 | if (windows.is_the_target) { | |
| 1443 | if (builtin.os == .windows) { | |
| 1444 | 1444 | if (isCygwinPty(handle)) |
| 1445 | 1445 | return true; |
| 1446 | 1446 | |
| ... | ... | @@ -1450,10 +1450,10 @@ pub fn isatty(handle: fd_t) bool { |
| 1450 | 1450 | if (builtin.link_libc) { |
| 1451 | 1451 | return system.isatty(handle) != 0; |
| 1452 | 1452 | } |
| 1453 | if (wasi.is_the_target) { | |
| 1453 | if (builtin.os == .wasi) { | |
| 1454 | 1454 | @compileError("TODO implement std.os.isatty for WASI"); |
| 1455 | 1455 | } |
| 1456 | if (linux.is_the_target) { | |
| 1456 | if (builtin.os == .linux) { | |
| 1457 | 1457 | var wsz: linux.winsize = undefined; |
| 1458 | 1458 | return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, isize(handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0; |
| 1459 | 1459 | } |
| ... | ... | @@ -1461,7 +1461,7 @@ pub fn isatty(handle: fd_t) bool { |
| 1461 | 1461 | } |
| 1462 | 1462 | |
| 1463 | 1463 | pub fn isCygwinPty(handle: fd_t) bool { |
| 1464 | if (!windows.is_the_target) return false; | |
| 1464 | if (builtin.os != .windows) return false; | |
| 1465 | 1465 | |
| 1466 | 1466 | const size = @sizeOf(windows.FILE_NAME_INFO); |
| 1467 | 1467 | var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = [_]u8{0} ** (size + windows.MAX_PATH); |
| ... | ... | @@ -1961,7 +1961,7 @@ pub const FStatError = error{SystemResources} || UnexpectedError; |
| 1961 | 1961 | |
| 1962 | 1962 | pub fn fstat(fd: fd_t) FStatError!Stat { |
| 1963 | 1963 | var stat: Stat = undefined; |
| 1964 | if (darwin.is_the_target) { | |
| 1964 | if (comptime std.Target.current.isDarwin()) { | |
| 1965 | 1965 | switch (darwin.getErrno(darwin.@"fstat$INODE64"(fd, &stat))) { |
| 1966 | 1966 | 0 => return stat, |
| 1967 | 1967 | EINVAL => unreachable, |
| ... | ... | @@ -2227,7 +2227,7 @@ pub const AccessError = error{ |
| 2227 | 2227 | /// check user's permissions for a file |
| 2228 | 2228 | /// TODO currently this assumes `mode` is `F_OK` on Windows. |
| 2229 | 2229 | pub fn access(path: []const u8, mode: u32) AccessError!void { |
| 2230 | if (windows.is_the_target) { | |
| 2230 | if (builtin.os == .windows) { | |
| 2231 | 2231 | const path_w = try windows.sliceToPrefixedFileW(path); |
| 2232 | 2232 | _ = try windows.GetFileAttributesW(&path_w); |
| 2233 | 2233 | return; |
| ... | ... | @@ -2238,7 +2238,7 @@ pub fn access(path: []const u8, mode: u32) AccessError!void { |
| 2238 | 2238 | |
| 2239 | 2239 | /// Same as `access` except `path` is null-terminated. |
| 2240 | 2240 | pub fn accessC(path: [*]const u8, mode: u32) AccessError!void { |
| 2241 | if (windows.is_the_target) { | |
| 2241 | if (builtin.os == .windows) { | |
| 2242 | 2242 | const path_w = try windows.cStrToPrefixedFileW(path); |
| 2243 | 2243 | _ = try windows.GetFileAttributesW(&path_w); |
| 2244 | 2244 | return; |
| ... | ... | @@ -2358,7 +2358,7 @@ pub const SeekError = error{Unseekable} || UnexpectedError; |
| 2358 | 2358 | |
| 2359 | 2359 | /// Repositions read/write file offset relative to the beginning. |
| 2360 | 2360 | pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void { |
| 2361 | if (linux.is_the_target and !builtin.link_libc and @sizeOf(usize) == 4) { | |
| 2361 | if (builtin.os == .linux and !builtin.link_libc and @sizeOf(usize) == 4) { | |
| 2362 | 2362 | var result: u64 = undefined; |
| 2363 | 2363 | switch (errno(system.llseek(fd, offset, &result, SEEK_SET))) { |
| 2364 | 2364 | 0 => return, |
| ... | ... | @@ -2370,7 +2370,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void { |
| 2370 | 2370 | else => |err| return unexpectedErrno(err), |
| 2371 | 2371 | } |
| 2372 | 2372 | } |
| 2373 | if (windows.is_the_target) { | |
| 2373 | if (builtin.os == .windows) { | |
| 2374 | 2374 | return windows.SetFilePointerEx_BEGIN(fd, offset); |
| 2375 | 2375 | } |
| 2376 | 2376 | const ipos = @bitCast(i64, offset); // the OS treats this as unsigned |
| ... | ... | @@ -2387,7 +2387,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void { |
| 2387 | 2387 | |
| 2388 | 2388 | /// Repositions read/write file offset relative to the current offset. |
| 2389 | 2389 | pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void { |
| 2390 | if (linux.is_the_target and !builtin.link_libc and @sizeOf(usize) == 4) { | |
| 2390 | if (builtin.os == .linux and !builtin.link_libc and @sizeOf(usize) == 4) { | |
| 2391 | 2391 | var result: u64 = undefined; |
| 2392 | 2392 | switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_CUR))) { |
| 2393 | 2393 | 0 => return, |
| ... | ... | @@ -2399,7 +2399,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void { |
| 2399 | 2399 | else => |err| return unexpectedErrno(err), |
| 2400 | 2400 | } |
| 2401 | 2401 | } |
| 2402 | if (windows.is_the_target) { | |
| 2402 | if (builtin.os == .windows) { | |
| 2403 | 2403 | return windows.SetFilePointerEx_CURRENT(fd, offset); |
| 2404 | 2404 | } |
| 2405 | 2405 | switch (errno(system.lseek(fd, offset, SEEK_CUR))) { |
| ... | ... | @@ -2415,7 +2415,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void { |
| 2415 | 2415 | |
| 2416 | 2416 | /// Repositions read/write file offset relative to the end. |
| 2417 | 2417 | pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void { |
| 2418 | if (linux.is_the_target and !builtin.link_libc and @sizeOf(usize) == 4) { | |
| 2418 | if (builtin.os == .linux and !builtin.link_libc and @sizeOf(usize) == 4) { | |
| 2419 | 2419 | var result: u64 = undefined; |
| 2420 | 2420 | switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_END))) { |
| 2421 | 2421 | 0 => return, |
| ... | ... | @@ -2427,7 +2427,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void { |
| 2427 | 2427 | else => |err| return unexpectedErrno(err), |
| 2428 | 2428 | } |
| 2429 | 2429 | } |
| 2430 | if (windows.is_the_target) { | |
| 2430 | if (builtin.os == .windows) { | |
| 2431 | 2431 | return windows.SetFilePointerEx_END(fd, offset); |
| 2432 | 2432 | } |
| 2433 | 2433 | switch (errno(system.lseek(fd, offset, SEEK_END))) { |
| ... | ... | @@ -2443,7 +2443,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void { |
| 2443 | 2443 | |
| 2444 | 2444 | /// Returns the read/write file offset relative to the beginning. |
| 2445 | 2445 | pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 { |
| 2446 | if (linux.is_the_target and !builtin.link_libc and @sizeOf(usize) == 4) { | |
| 2446 | if (builtin.os == .linux and !builtin.link_libc and @sizeOf(usize) == 4) { | |
| 2447 | 2447 | var result: u64 = undefined; |
| 2448 | 2448 | switch (errno(system.llseek(fd, 0, &result, SEEK_CUR))) { |
| 2449 | 2449 | 0 => return result, |
| ... | ... | @@ -2455,7 +2455,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 { |
| 2455 | 2455 | else => |err| return unexpectedErrno(err), |
| 2456 | 2456 | } |
| 2457 | 2457 | } |
| 2458 | if (windows.is_the_target) { | |
| 2458 | if (builtin.os == .windows) { | |
| 2459 | 2459 | return windows.SetFilePointerEx_CURRENT_get(fd); |
| 2460 | 2460 | } |
| 2461 | 2461 | const rc = system.lseek(fd, 0, SEEK_CUR); |
| ... | ... | @@ -2504,7 +2504,7 @@ pub const RealPathError = error{ |
| 2504 | 2504 | /// The return value is a slice of `out_buffer`, but not necessarily from the beginning. |
| 2505 | 2505 | /// See also `realpathC` and `realpathW`. |
| 2506 | 2506 | pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { |
| 2507 | if (windows.is_the_target) { | |
| 2507 | if (builtin.os == .windows) { | |
| 2508 | 2508 | const pathname_w = try windows.sliceToPrefixedFileW(pathname); |
| 2509 | 2509 | return realpathW(&pathname_w, out_buffer); |
| 2510 | 2510 | } |
| ... | ... | @@ -2514,11 +2514,11 @@ pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathE |
| 2514 | 2514 | |
| 2515 | 2515 | /// Same as `realpath` except `pathname` is null-terminated. |
| 2516 | 2516 | pub fn realpathC(pathname: [*]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { |
| 2517 | if (windows.is_the_target) { | |
| 2517 | if (builtin.os == .windows) { | |
| 2518 | 2518 | const pathname_w = try windows.cStrToPrefixedFileW(pathname); |
| 2519 | 2519 | return realpathW(&pathname_w, out_buffer); |
| 2520 | 2520 | } |
| 2521 | if (linux.is_the_target and !builtin.link_libc) { | |
| 2521 | if (builtin.os == .linux and !builtin.link_libc) { | |
| 2522 | 2522 | const fd = try openC(pathname, linux.O_PATH | linux.O_NONBLOCK | linux.O_CLOEXEC, 0); |
| 2523 | 2523 | defer close(fd); |
| 2524 | 2524 | |
| ... | ... | @@ -2596,9 +2596,12 @@ pub fn nanosleep(seconds: u64, nanoseconds: u64) void { |
| 2596 | 2596 | } |
| 2597 | 2597 | } |
| 2598 | 2598 | |
| 2599 | pub fn dl_iterate_phdr(comptime T: type, callback: extern fn (info: *dl_phdr_info, size: usize, data: ?*T) i32, data: ?*T) isize { | |
| 2600 | // This is implemented only for systems using ELF executables | |
| 2601 | if (windows.is_the_target or builtin.os == .uefi or wasi.is_the_target or darwin.is_the_target) | |
| 2599 | pub fn dl_iterate_phdr( | |
| 2600 | comptime T: type, | |
| 2601 | callback: extern fn (info: *dl_phdr_info, size: usize, data: ?*T) i32, | |
| 2602 | data: ?*T, | |
| 2603 | ) isize { | |
| 2604 | if (builtin.object_format != .elf) | |
| 2602 | 2605 | @compileError("dl_iterate_phdr is not available for this target"); |
| 2603 | 2606 | |
| 2604 | 2607 | if (builtin.link_libc) { |
| ... | ... | @@ -2737,7 +2740,7 @@ pub const SigaltstackError = error{ |
| 2737 | 2740 | } || UnexpectedError; |
| 2738 | 2741 | |
| 2739 | 2742 | pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void { |
| 2740 | if (windows.is_the_target or uefi.is_the_target or wasi.is_the_target) | |
| 2743 | if (builtin.os == .windows or builtin.os == .uefi or builtin.os == .wasi) | |
| 2741 | 2744 | @compileError("std.os.sigaltstack not available for this target"); |
| 2742 | 2745 | |
| 2743 | 2746 | switch (errno(system.sigaltstack(ss, old_ss))) { |
| ... | ... | @@ -2809,7 +2812,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { |
| 2809 | 2812 | else => |err| return unexpectedErrno(err), |
| 2810 | 2813 | } |
| 2811 | 2814 | } |
| 2812 | if (linux.is_the_target) { | |
| 2815 | if (builtin.os == .linux) { | |
| 2813 | 2816 | var uts: utsname = undefined; |
| 2814 | 2817 | switch (errno(system.uname(&uts))) { |
| 2815 | 2818 | 0 => { |
lib/std/os/darwin.zig-4| ... | ... | @@ -1,8 +1,4 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("../std.zig"); |
| 3 | pub const is_the_target = switch (builtin.os) { | |
| 4 | .macosx, .tvos, .watchos, .ios => true, | |
| 5 | else => false, | |
| 6 | }; | |
| 7 | 3 | pub usingnamespace std.c; |
| 8 | 4 | pub usingnamespace @import("bits.zig"); |
lib/std/os/freebsd.zig-2| ... | ... | @@ -1,5 +1,3 @@ |
| 1 | 1 | const std = @import("../std.zig"); |
| 2 | const builtin = @import("builtin"); | |
| 3 | pub const is_the_target = builtin.os == .freebsd; | |
| 4 | 2 | pub usingnamespace std.c; |
| 5 | 3 | pub usingnamespace @import("bits.zig"); |
lib/std/os/linux.zig+1-2| ... | ... | @@ -13,7 +13,6 @@ const elf = std.elf; |
| 13 | 13 | const vdso = @import("linux/vdso.zig"); |
| 14 | 14 | const dl = @import("../dynamic_library.zig"); |
| 15 | 15 | |
| 16 | pub const is_the_target = builtin.os == .linux; | |
| 17 | 16 | pub usingnamespace switch (builtin.arch) { |
| 18 | 17 | .x86_64 => @import("linux/x86_64.zig"), |
| 19 | 18 | .aarch64 => @import("linux/arm64.zig"), |
| ... | ... | @@ -1079,7 +1078,7 @@ pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32 |
| 1079 | 1078 | } |
| 1080 | 1079 | |
| 1081 | 1080 | test "" { |
| 1082 | if (is_the_target) { | |
| 1081 | if (builtin.os == .linux) { | |
| 1083 | 1082 | _ = @import("linux/test.zig"); |
| 1084 | 1083 | } |
| 1085 | 1084 | } |
lib/std/os/netbsd.zig-2| ... | ... | @@ -1,5 +1,3 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | 1 | const std = @import("../std.zig"); |
| 3 | pub const is_the_target = builtin.os == .netbsd; | |
| 4 | 2 | pub usingnamespace std.c; |
| 5 | 3 | pub usingnamespace @import("bits.zig"); |
lib/std/os/test.zig+3-3| ... | ... | @@ -53,7 +53,7 @@ test "std.Thread.getCurrentId" { |
| 53 | 53 | thread.wait(); |
| 54 | 54 | if (Thread.use_pthreads) { |
| 55 | 55 | expect(thread_current_id == thread_id); |
| 56 | } else if (os.windows.is_the_target) { | |
| 56 | } else if (builtin.os == .windows) { | |
| 57 | 57 | expect(Thread.getCurrentId() != thread_current_id); |
| 58 | 58 | } else { |
| 59 | 59 | // If the thread completes very quickly, then thread_id can be 0. See the |
| ... | ... | @@ -212,7 +212,7 @@ test "dl_iterate_phdr" { |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | test "gethostname" { |
| 215 | if (os.windows.is_the_target) | |
| 215 | if (builtin.os == .windows) | |
| 216 | 216 | return error.SkipZigTest; |
| 217 | 217 | |
| 218 | 218 | var buf: [os.HOST_NAME_MAX]u8 = undefined; |
| ... | ... | @@ -221,7 +221,7 @@ test "gethostname" { |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | test "pipe" { |
| 224 | if (os.windows.is_the_target) | |
| 224 | if (builtin.os == .windows) | |
| 225 | 225 | return error.SkipZigTest; |
| 226 | 226 | |
| 227 | 227 | var fds = try os.pipe(); |
lib/std/os/uefi.zig+13-3| ... | ... | @@ -1,16 +1,15 @@ |
| 1 | 1 | /// A protocol is an interface identified by a GUID. |
| 2 | 2 | pub const protocols = @import("uefi/protocols.zig"); |
| 3 | ||
| 3 | 4 | /// Status codes returned by EFI interfaces |
| 4 | 5 | pub const status = @import("uefi/status.zig"); |
| 5 | 6 | pub const tables = @import("uefi/tables.zig"); |
| 6 | 7 | |
| 7 | 8 | const fmt = @import("std").fmt; |
| 8 | 9 | |
| 9 | const builtin = @import("builtin"); | |
| 10 | pub const is_the_target = builtin.os == .uefi; | |
| 11 | ||
| 12 | 10 | /// The EFI image's handle that is passed to its entry point. |
| 13 | 11 | pub var handle: Handle = undefined; |
| 12 | ||
| 14 | 13 | /// A pointer to the EFI System Table that is passed to the EFI image's entry point. |
| 15 | 14 | pub var system_table: *tables.SystemTable = undefined; |
| 16 | 15 | |
| ... | ... | @@ -50,26 +49,35 @@ pub const Handle = *@OpaqueType(); |
| 50 | 49 | pub const Time = extern struct { |
| 51 | 50 | /// 1900 - 9999 |
| 52 | 51 | year: u16, |
| 52 | ||
| 53 | 53 | /// 1 - 12 |
| 54 | 54 | month: u8, |
| 55 | ||
| 55 | 56 | /// 1 - 31 |
| 56 | 57 | day: u8, |
| 58 | ||
| 57 | 59 | /// 0 - 23 |
| 58 | 60 | hour: u8, |
| 61 | ||
| 59 | 62 | /// 0 - 59 |
| 60 | 63 | minute: u8, |
| 64 | ||
| 61 | 65 | /// 0 - 59 |
| 62 | 66 | second: u8, |
| 63 | 67 | _pad1: u8, |
| 68 | ||
| 64 | 69 | /// 0 - 999999999 |
| 65 | 70 | nanosecond: u32, |
| 71 | ||
| 66 | 72 | /// The time's offset in minutes from UTC. |
| 67 | 73 | /// Allowed values are -1440 to 1440 or unspecified_timezone |
| 68 | 74 | timezone: i16, |
| 69 | 75 | daylight: packed struct { |
| 70 | 76 | _pad1: u6, |
| 77 | ||
| 71 | 78 | /// If true, the time has been adjusted for daylight savings time. |
| 72 | 79 | in_daylight: bool, |
| 80 | ||
| 73 | 81 | /// If true, the time is affected by daylight savings time. |
| 74 | 82 | adjust_daylight: bool, |
| 75 | 83 | }, |
| ... | ... | @@ -83,8 +91,10 @@ pub const Time = extern struct { |
| 83 | 91 | pub const TimeCapabilities = extern struct { |
| 84 | 92 | /// Resolution in Hz |
| 85 | 93 | resolution: u32, |
| 94 | ||
| 86 | 95 | /// Accuracy in an error rate of 1e-6 parts per million. |
| 87 | 96 | accuracy: u32, |
| 97 | ||
| 88 | 98 | /// If true, a time set operation clears the device's time below the resolution level. |
| 89 | 99 | sets_to_zero: bool, |
| 90 | 100 | }; |
lib/std/os/wasi.zig-2| ... | ... | @@ -1,10 +1,8 @@ |
| 1 | 1 | // Based on https://github.com/CraneStation/wasi-sysroot/blob/wasi/libc-bottom-half/headers/public/wasi/core.h |
| 2 | 2 | // and https://github.com/WebAssembly/WASI/blob/master/design/WASI-core.md |
| 3 | const builtin = @import("builtin"); | |
| 4 | 3 | const std = @import("std"); |
| 5 | 4 | const assert = std.debug.assert; |
| 6 | 5 | |
| 7 | pub const is_the_target = builtin.os == .wasi; | |
| 8 | 6 | pub usingnamespace @import("bits.zig"); |
| 9 | 7 | |
| 10 | 8 | comptime { |
lib/std/os/windows.zig-1| ... | ... | @@ -11,7 +11,6 @@ const assert = std.debug.assert; |
| 11 | 11 | const math = std.math; |
| 12 | 12 | const maxInt = std.math.maxInt; |
| 13 | 13 | |
| 14 | pub const is_the_target = builtin.os == .windows; | |
| 15 | 14 | pub const advapi32 = @import("windows/advapi32.zig"); |
| 16 | 15 | pub const kernel32 = @import("windows/kernel32.zig"); |
| 17 | 16 | pub const ntdll = @import("windows/ntdll.zig"); |
lib/std/process.zig+2-2| ... | ... | @@ -39,7 +39,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap { |
| 39 | 39 | var result = BufMap.init(allocator); |
| 40 | 40 | errdefer result.deinit(); |
| 41 | 41 | |
| 42 | if (os.windows.is_the_target) { | |
| 42 | if (builtin.os == .windows) { | |
| 43 | 43 | const ptr = try os.windows.GetEnvironmentStringsW(); |
| 44 | 44 | defer os.windows.FreeEnvironmentStringsW(ptr); |
| 45 | 45 | |
| ... | ... | @@ -129,7 +129,7 @@ pub const GetEnvVarOwnedError = error{ |
| 129 | 129 | /// Caller must free returned memory. |
| 130 | 130 | /// TODO make this go through libc when we have it |
| 131 | 131 | pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwnedError![]u8 { |
| 132 | if (os.windows.is_the_target) { | |
| 132 | if (builtin.os == .windows) { | |
| 133 | 133 | const key_with_null = try std.unicode.utf8ToUtf16LeWithNull(allocator, key); |
| 134 | 134 | defer allocator.free(key_with_null); |
| 135 | 135 |
lib/std/target.zig+3| ... | ... | @@ -1,6 +1,9 @@ |
| 1 | 1 | const std = @import("std.zig"); |
| 2 | 2 | const builtin = std.builtin; |
| 3 | 3 | |
| 4 | /// TODO Nearly all the functions in this namespace would be | |
| 5 | /// better off if https://github.com/ziglang/zig/issues/425 | |
| 6 | /// was solved. | |
| 4 | 7 | pub const Target = union(enum) { |
| 5 | 8 | Native: void, |
| 6 | 9 | Cross: Cross, |
lib/std/thread.zig+5-5| ... | ... | @@ -9,7 +9,7 @@ const assert = std.debug.assert; |
| 9 | 9 | pub const Thread = struct { |
| 10 | 10 | data: Data, |
| 11 | 11 | |
| 12 | pub const use_pthreads = !windows.is_the_target and builtin.link_libc; | |
| 12 | pub const use_pthreads = builtin.os != .windows and builtin.link_libc; | |
| 13 | 13 | |
| 14 | 14 | /// Represents a kernel thread handle. |
| 15 | 15 | /// May be an integer or a pointer depending on the platform. |
| ... | ... | @@ -309,7 +309,7 @@ pub const Thread = struct { |
| 309 | 309 | os.EINVAL => unreachable, |
| 310 | 310 | else => return os.unexpectedErrno(@intCast(usize, err)), |
| 311 | 311 | } |
| 312 | } else if (os.linux.is_the_target) { | |
| 312 | } else if (builtin.os == .linux) { | |
| 313 | 313 | var flags: u32 = os.CLONE_VM | os.CLONE_FS | os.CLONE_FILES | os.CLONE_SIGHAND | |
| 314 | 314 | os.CLONE_THREAD | os.CLONE_SYSVSEM | os.CLONE_PARENT_SETTID | os.CLONE_CHILD_CLEARTID | |
| 315 | 315 | os.CLONE_DETACHED; |
| ... | ... | @@ -342,18 +342,18 @@ pub const Thread = struct { |
| 342 | 342 | }; |
| 343 | 343 | |
| 344 | 344 | pub fn cpuCount() CpuCountError!usize { |
| 345 | if (os.linux.is_the_target) { | |
| 345 | if (builtin.os == .linux) { | |
| 346 | 346 | const cpu_set = try os.sched_getaffinity(0); |
| 347 | 347 | return usize(os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast |
| 348 | 348 | } |
| 349 | if (os.windows.is_the_target) { | |
| 349 | if (builtin.os == .windows) { | |
| 350 | 350 | var system_info: windows.SYSTEM_INFO = undefined; |
| 351 | 351 | windows.kernel32.GetSystemInfo(&system_info); |
| 352 | 352 | return @intCast(usize, system_info.dwNumberOfProcessors); |
| 353 | 353 | } |
| 354 | 354 | var count: c_int = undefined; |
| 355 | 355 | var count_len: usize = @sizeOf(c_int); |
| 356 | const name = if (os.darwin.is_the_target) c"hw.logicalcpu" else c"hw.ncpu"; | |
| 356 | const name = if (comptime std.Target.current.isDarwin()) c"hw.logicalcpu" else c"hw.ncpu"; | |
| 357 | 357 | os.sysctlbynameC(name, &count, &count_len, null, 0) catch |err| switch (err) { |
| 358 | 358 | error.NameTooLong => unreachable, |
| 359 | 359 | else => |e| return e, |
lib/std/time.zig+10-10| ... | ... | @@ -9,7 +9,7 @@ pub const epoch = @import("time/epoch.zig"); |
| 9 | 9 | |
| 10 | 10 | /// Spurious wakeups are possible and no precision of timing is guaranteed. |
| 11 | 11 | pub fn sleep(nanoseconds: u64) void { |
| 12 | if (os.windows.is_the_target) { | |
| 12 | if (builtin.os == .windows) { | |
| 13 | 13 | const ns_per_ms = ns_per_s / ms_per_s; |
| 14 | 14 | const big_ms_from_ns = nanoseconds / ns_per_ms; |
| 15 | 15 | const ms = math.cast(os.windows.DWORD, big_ms_from_ns) catch math.maxInt(os.windows.DWORD); |
| ... | ... | @@ -30,7 +30,7 @@ pub fn timestamp() u64 { |
| 30 | 30 | /// Get the posix timestamp, UTC, in milliseconds |
| 31 | 31 | /// TODO audit this function. is it possible to return an error? |
| 32 | 32 | pub fn milliTimestamp() u64 { |
| 33 | if (os.windows.is_the_target) { | |
| 33 | if (builtin.os == .windows) { | |
| 34 | 34 | //FileTime has a granularity of 100 nanoseconds |
| 35 | 35 | // and uses the NTFS/Windows epoch |
| 36 | 36 | var ft: os.windows.FILETIME = undefined; |
| ... | ... | @@ -41,7 +41,7 @@ pub fn milliTimestamp() u64 { |
| 41 | 41 | const ft64 = (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime; |
| 42 | 42 | return @divFloor(ft64, hns_per_ms) - -epoch_adj; |
| 43 | 43 | } |
| 44 | if (os.wasi.is_the_target and !builtin.link_libc) { | |
| 44 | if (builtin.os == .wasi and !builtin.link_libc) { | |
| 45 | 45 | var ns: os.wasi.timestamp_t = undefined; |
| 46 | 46 | |
| 47 | 47 | // TODO: Verify that precision is ignored |
| ... | ... | @@ -51,7 +51,7 @@ pub fn milliTimestamp() u64 { |
| 51 | 51 | const ns_per_ms = 1000; |
| 52 | 52 | return @divFloor(ns, ns_per_ms); |
| 53 | 53 | } |
| 54 | if (os.darwin.is_the_target) { | |
| 54 | if (comptime std.Target.current.isDarwin()) { | |
| 55 | 55 | var tv: os.darwin.timeval = undefined; |
| 56 | 56 | var err = os.darwin.gettimeofday(&tv, null); |
| 57 | 57 | assert(err == 0); |
| ... | ... | @@ -126,11 +126,11 @@ pub const Timer = struct { |
| 126 | 126 | pub fn start() Error!Timer { |
| 127 | 127 | var self: Timer = undefined; |
| 128 | 128 | |
| 129 | if (os.windows.is_the_target) { | |
| 129 | if (builtin.os == .windows) { | |
| 130 | 130 | self.frequency = os.windows.QueryPerformanceFrequency(); |
| 131 | 131 | self.resolution = @divFloor(ns_per_s, self.frequency); |
| 132 | 132 | self.start_time = os.windows.QueryPerformanceCounter(); |
| 133 | } else if (os.darwin.is_the_target) { | |
| 133 | } else if (comptime std.Target.current.isDarwin()) { | |
| 134 | 134 | os.darwin.mach_timebase_info(&self.frequency); |
| 135 | 135 | self.resolution = @divFloor(self.frequency.numer, self.frequency.denom); |
| 136 | 136 | self.start_time = os.darwin.mach_absolute_time(); |
| ... | ... | @@ -154,10 +154,10 @@ pub const Timer = struct { |
| 154 | 154 | /// Reads the timer value since start or the last reset in nanoseconds |
| 155 | 155 | pub fn read(self: *Timer) u64 { |
| 156 | 156 | var clock = clockNative() - self.start_time; |
| 157 | if (os.windows.is_the_target) { | |
| 157 | if (builtin.os == .windows) { | |
| 158 | 158 | return @divFloor(clock * ns_per_s, self.frequency); |
| 159 | 159 | } |
| 160 | if (os.darwin.is_the_target) { | |
| 160 | if (comptime std.Target.current.isDarwin()) { | |
| 161 | 161 | return @divFloor(clock * self.frequency.numer, self.frequency.denom); |
| 162 | 162 | } |
| 163 | 163 | return clock; |
| ... | ... | @@ -177,10 +177,10 @@ pub const Timer = struct { |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | fn clockNative() u64 { |
| 180 | if (os.windows.is_the_target) { | |
| 180 | if (builtin.os == .windows) { | |
| 181 | 181 | return os.windows.QueryPerformanceCounter(); |
| 182 | 182 | } |
| 183 | if (os.darwin.is_the_target) { | |
| 183 | if (comptime std.Target.current.isDarwin()) { | |
| 184 | 184 | return os.darwin.mach_absolute_time(); |
| 185 | 185 | } |
| 186 | 186 | var ts: os.timespec = undefined; |