authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-24 01:06:03-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-24 01:14:52-04:00
log60cd11bd4b48e4dfdf11d1f25cb1ee842a49ee1d
tree457ea0157f0f42dccf905593426154be8682812b
parent8591731f2b938b2b55b05181d5ec0e27f79c86fa
signaturelock-open Commit is signed but in an unrecognized format.

get rid of std.os.foo.is_the_target

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 {
20002000 }
20012001
20022002 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";
20042004 const env_map = self.getEnvMap();
20052005 const prev_path = env_map.get(PATH) orelse {
20062006 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;
3636/// export a weak symbol here, to be overridden by the real one.
3737pub extern "c" var _mh_execute_header: mach_hdr = undefined;
3838comptime {
39 if (std.os.darwin.is_the_target) {
39 if (std.Target.current.isDarwin()) {
4040 @export("_mh_execute_header", _mh_execute_header, .Weak);
4141 }
4242}
lib/std/child_process.zig+12-12
......@@ -17,9 +17,9 @@ const TailQueue = std.TailQueue;
1717const maxInt = std.math.maxInt;
1818
1919pub 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,
2323
2424 allocator: *mem.Allocator,
2525
......@@ -39,16 +39,16 @@ pub const ChildProcess = struct {
3939 stderr_behavior: StdIo,
4040
4141 /// 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,
4343
4444 /// 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,
4646
4747 /// Set to change the current working directory when spawning the child process.
4848 cwd: ?[]const u8,
4949
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,
5252
5353 pub const SpawnError = error{OutOfMemory} || os.ExecveError || os.SetIdError ||
5454 os.ChangeCurDirError || windows.CreateProcessError;
......@@ -82,8 +82,8 @@ pub const ChildProcess = struct {
8282 .term = null,
8383 .env_map = null,
8484 .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,
8787 .stdin = null,
8888 .stdout = null,
8989 .stderr = null,
......@@ -103,7 +103,7 @@ pub const ChildProcess = struct {
103103
104104 /// On success must call `kill` or `wait`.
105105 pub fn spawn(self: *ChildProcess) !void {
106 if (os.windows.is_the_target) {
106 if (builtin.os == .windows) {
107107 return self.spawnWindows();
108108 } else {
109109 return self.spawnPosix();
......@@ -117,7 +117,7 @@ pub const ChildProcess = struct {
117117
118118 /// Forcibly terminates child process and then cleans up all resources.
119119 pub fn kill(self: *ChildProcess) !Term {
120 if (os.windows.is_the_target) {
120 if (builtin.os == .windows) {
121121 return self.killWindows(1);
122122 } else {
123123 return self.killPosix();
......@@ -147,7 +147,7 @@ pub const ChildProcess = struct {
147147
148148 /// Blocks until child process terminates and then cleans up all resources.
149149 pub fn wait(self: *ChildProcess) !Term {
150 if (os.windows.is_the_target) {
150 if (builtin.os == .windows) {
151151 return self.waitWindows();
152152 } else {
153153 return self.waitPosix();
lib/std/debug.zig+8-8
......@@ -133,7 +133,7 @@ pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
133133/// chopping off the irrelevant frames and shifting so that the returned addresses pointer
134134/// equals the passed in addresses pointer.
135135pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace) void {
136 if (windows.is_the_target) {
136 if (builtin.os == .windows) {
137137 const addrs = stack_trace.instruction_addresses;
138138 const u32_addrs_len = @intCast(u32, addrs.len);
139139 const first_addr = first_address orelse {
......@@ -310,7 +310,7 @@ pub const StackIterator = struct {
310310};
311311
312312pub 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) {
314314 return writeCurrentStackTraceWindows(out_stream, debug_info, tty_color, start_addr);
315315 }
316316 var it = StackIterator.init(start_addr);
......@@ -342,10 +342,10 @@ pub fn writeCurrentStackTraceWindows(
342342/// TODO once https://github.com/ziglang/zig/issues/3157 is fully implemented,
343343/// make this `noasync fn` and remove the individual noasync calls.
344344pub 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) {
346346 return noasync printSourceAtAddressWindows(debug_info, out_stream, address, tty_color);
347347 }
348 if (os.darwin.is_the_target) {
348 if (comptime std.Target.current.isDarwin()) {
349349 return noasync printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color);
350350 }
351351 return noasync printSourceAtAddressPosix(debug_info, out_stream, address, tty_color);
......@@ -832,10 +832,10 @@ pub const OpenSelfDebugInfoError = error{
832832pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {
833833 if (builtin.strip_debug_info)
834834 return error.MissingDebugInfo;
835 if (windows.is_the_target) {
835 if (builtin.os == .windows) {
836836 return noasync openSelfDebugInfoWindows(allocator);
837837 }
838 if (os.darwin.is_the_target) {
838 if (comptime std.Target.current.isDarwin()) {
839839 return noasync openSelfDebugInfoMacOs(allocator);
840840 }
841841 return noasync openSelfDebugInfoPosix(allocator);
......@@ -2364,7 +2364,7 @@ pub fn attachSegfaultHandler() void {
23642364 if (!have_segfault_handling_support) {
23652365 @compileError("segfault handler not supported for this target");
23662366 }
2367 if (windows.is_the_target) {
2367 if (builtin.os == .windows) {
23682368 windows_segfault_handle = windows.kernel32.AddVectoredExceptionHandler(0, handleSegfaultWindows);
23692369 return;
23702370 }
......@@ -2378,7 +2378,7 @@ pub fn attachSegfaultHandler() void {
23782378}
23792379
23802380fn resetSegfaultHandler() void {
2381 if (windows.is_the_target) {
2381 if (builtin.os == .windows) {
23822382 if (windows_segfault_handle) |handle| {
23832383 assert(windows.kernel32.RemoveVectoredExceptionHandler(handle) != 0);
23842384 windows_segfault_handle = null;
lib/std/event/channel.zig+1-1
......@@ -307,7 +307,7 @@ test "std.event.Channel" {
307307 // https://github.com/ziglang/zig/issues/1908
308308 if (builtin.single_threaded) return error.SkipZigTest;
309309 // 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;
311311
312312 var loop: Loop = undefined;
313313 // TODO make a multi threaded test
lib/std/event/fs.zig+1-1
......@@ -909,7 +909,7 @@ fn hashString(s: []const u16) u32 {
909909// var close_op_consumed = false;
910910// defer if (!close_op_consumed) close_op.finish();
911911//
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;
913913// const mode = 0;
914914// const fd = try await (async openPosix(self.channel.loop, resolved_path, flags, mode) catch unreachable);
915915// close_op.setHandle(fd);
lib/std/event/future.zig+1-1
......@@ -86,7 +86,7 @@ test "std.event.Future" {
8686 // https://github.com/ziglang/zig/issues/1908
8787 if (builtin.single_threaded) return error.SkipZigTest;
8888 // 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;
9090
9191 const allocator = std.heap.direct_allocator;
9292
lib/std/event/lock.zig+1-1
......@@ -119,7 +119,7 @@ test "std.event.Lock" {
119119 // TODO https://github.com/ziglang/zig/issues/1908
120120 if (builtin.single_threaded) return error.SkipZigTest;
121121 // 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;
123123
124124 const allocator = std.heap.direct_allocator;
125125
lib/std/fs.zig+9-9
......@@ -255,7 +255,7 @@ pub const AtomicFile = struct {
255255 assert(!self.finished);
256256 self.file.close();
257257 self.finished = true;
258 if (os.windows.is_the_target) {
258 if (builtin.os == .windows) {
259259 const dest_path_w = try os.windows.sliceToPrefixedFileW(self.dest_path);
260260 const tmp_path_w = try os.windows.cStrToPrefixedFileW(&self.tmp_path_buf);
261261 return os.renameW(&tmp_path_w, &dest_path_w);
......@@ -659,7 +659,7 @@ pub const Dir = struct {
659659 /// Closing the returned `Dir` is checked illegal behavior.
660660 /// On POSIX targets, this function is comptime-callable.
661661 pub fn cwd() Dir {
662 if (os.windows.is_the_target) {
662 if (builtin.os == .windows) {
663663 return Dir{ .fd = os.windows.peb().ProcessParameters.CurrentDirectory.Handle };
664664 } else {
665665 return Dir{ .fd = os.AT_FDCWD };
......@@ -711,7 +711,7 @@ pub const Dir = struct {
711711
712712 /// Call `close` on the result when done.
713713 pub fn openDir(self: Dir, sub_path: []const u8) OpenError!Dir {
714 if (os.windows.is_the_target) {
714 if (builtin.os == .windows) {
715715 const sub_path_w = try os.windows.sliceToPrefixedFileW(sub_path);
716716 return self.openDirW(&sub_path_w);
717717 }
......@@ -722,7 +722,7 @@ pub const Dir = struct {
722722
723723 /// Same as `openDir` except the parameter is null-terminated.
724724 pub fn openDirC(self: Dir, sub_path_c: [*]const u8) OpenError!Dir {
725 if (os.windows.is_the_target) {
725 if (builtin.os == .windows) {
726726 const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c);
727727 return self.openDirW(&sub_path_w);
728728 }
......@@ -829,7 +829,7 @@ pub const Dir = struct {
829829 /// Returns `error.DirNotEmpty` if the directory is not empty.
830830 /// To delete a directory recursively, see `deleteTree`.
831831 pub fn deleteDir(self: Dir, sub_path: []const u8) DeleteDirError!void {
832 if (os.windows.is_the_target) {
832 if (builtin.os == .windows) {
833833 const sub_path_w = try os.windows.sliceToPrefixedFileW(sub_path);
834834 return self.deleteDirW(&sub_path_w);
835835 }
......@@ -1146,10 +1146,10 @@ pub fn readLinkC(pathname_c: [*]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
11461146pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfExePathError;
11471147
11481148pub fn openSelfExe() OpenSelfExeError!File {
1149 if (os.linux.is_the_target) {
1149 if (builtin.os == .linux) {
11501150 return File.openReadC(c"/proc/self/exe");
11511151 }
1152 if (os.windows.is_the_target) {
1152 if (builtin.os == .windows) {
11531153 var buf: [os.windows.PATH_MAX_WIDE]u16 = undefined;
11541154 const wide_slice = try selfExePathW(&buf);
11551155 return File.openReadW(wide_slice.ptr);
......@@ -1180,7 +1180,7 @@ pub const SelfExePathError = os.ReadLinkError || os.SysCtlError;
11801180/// been deleted, the file path looks something like `/a/b/c/exe (deleted)`.
11811181/// TODO make the return type of this a null terminated pointer
11821182pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {
1183 if (os.darwin.is_the_target) {
1183 if (comptime std.Target.current.isDarwin()) {
11841184 var u32_len: u32 = out_buffer.len;
11851185 const rc = std.c._NSGetExecutablePath(out_buffer, &u32_len);
11861186 if (rc != 0) return error.NameTooLong;
......@@ -1228,7 +1228,7 @@ pub fn selfExeDirPathAlloc(allocator: *Allocator) ![]u8 {
12281228/// Get the directory path that contains the current executable.
12291229/// Returned value is a slice of out_buffer.
12301230pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]const u8 {
1231 if (os.linux.is_the_target) {
1231 if (builtin.os == .linux) {
12321232 // If the currently executing binary has been deleted,
12331233 // the file path looks something like `/a/b/c/exe (deleted)`
12341234 // 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 {
2727
2828 /// Call close to clean up.
2929 pub fn openRead(path: []const u8) OpenError!File {
30 if (windows.is_the_target) {
30 if (builtin.os == .windows) {
3131 const path_w = try windows.sliceToPrefixedFileW(path);
3232 return openReadW(&path_w);
3333 }
......@@ -37,7 +37,7 @@ pub const File = struct {
3737
3838 /// `openRead` except with a null terminated path
3939 pub fn openReadC(path: [*]const u8) OpenError!File {
40 if (windows.is_the_target) {
40 if (builtin.os == .windows) {
4141 const path_w = try windows.cStrToPrefixedFileW(path);
4242 return openReadW(&path_w);
4343 }
......@@ -69,7 +69,7 @@ pub const File = struct {
6969 /// If a file already exists in the destination it will be truncated.
7070 /// Call close to clean up.
7171 pub fn openWriteMode(path: []const u8, file_mode: Mode) OpenError!File {
72 if (windows.is_the_target) {
72 if (builtin.os == .windows) {
7373 const path_w = try windows.sliceToPrefixedFileW(path);
7474 return openWriteModeW(&path_w, file_mode);
7575 }
......@@ -79,7 +79,7 @@ pub const File = struct {
7979
8080 /// Same as `openWriteMode` except `path` is null-terminated.
8181 pub fn openWriteModeC(path: [*]const u8, file_mode: Mode) OpenError!File {
82 if (windows.is_the_target) {
82 if (builtin.os == .windows) {
8383 const path_w = try windows.cStrToPrefixedFileW(path);
8484 return openWriteModeW(&path_w, file_mode);
8585 }
......@@ -106,7 +106,7 @@ pub const File = struct {
106106 /// If a file already exists in the destination this returns OpenError.PathAlreadyExists
107107 /// Call close to clean up.
108108 pub fn openWriteNoClobber(path: []const u8, file_mode: Mode) OpenError!File {
109 if (windows.is_the_target) {
109 if (builtin.os == .windows) {
110110 const path_w = try windows.sliceToPrefixedFileW(path);
111111 return openWriteNoClobberW(&path_w, file_mode);
112112 }
......@@ -115,7 +115,7 @@ pub const File = struct {
115115 }
116116
117117 pub fn openWriteNoClobberC(path: [*]const u8, file_mode: Mode) OpenError!File {
118 if (windows.is_the_target) {
118 if (builtin.os == .windows) {
119119 const path_w = try windows.cStrToPrefixedFileW(path);
120120 return openWriteNoClobberW(&path_w, file_mode);
121121 }
......@@ -174,7 +174,7 @@ pub const File = struct {
174174
175175 /// Test whether ANSI escape codes will be treated as such.
176176 pub fn supportsAnsiEscapeCodes(self: File) bool {
177 if (windows.is_the_target) {
177 if (builtin.os == .windows) {
178178 return os.isCygwinPty(self.handle);
179179 }
180180 if (self.isTty()) {
......@@ -214,7 +214,7 @@ pub const File = struct {
214214 }
215215
216216 pub fn getEndPos(self: File) GetPosError!u64 {
217 if (windows.is_the_target) {
217 if (builtin.os == .windows) {
218218 return windows.GetFileSizeEx(self.handle);
219219 }
220220 return (try self.stat()).size;
......@@ -223,7 +223,7 @@ pub const File = struct {
223223 pub const ModeError = os.FStatError;
224224
225225 pub fn mode(self: File) ModeError!Mode {
226 if (windows.is_the_target) {
226 if (builtin.os == .windows) {
227227 return {};
228228 }
229229 return (try self.stat()).mode;
......@@ -246,7 +246,7 @@ pub const File = struct {
246246 pub const StatError = os.FStatError;
247247
248248 pub fn stat(self: File) StatError!Stat {
249 if (windows.is_the_target) {
249 if (builtin.os == .windows) {
250250 var io_status_block: windows.IO_STATUS_BLOCK = undefined;
251251 var info: windows.FILE_ALL_INFORMATION = undefined;
252252 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 {
291291 /// last modification timestamp in nanoseconds
292292 mtime: i64,
293293 ) UpdateTimesError!void {
294 if (windows.is_the_target) {
294 if (builtin.os == .windows) {
295295 const atime_ft = windows.nanoSecondsToFileTime(atime);
296296 const mtime_ft = windows.nanoSecondsToFileTime(mtime);
297297 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;
1313
1414pub const sep_windows = '\\';
1515pub const sep_posix = '/';
16pub const sep = if (windows.is_the_target) sep_windows else sep_posix;
16pub const sep = if (builtin.os == .windows) sep_windows else sep_posix;
1717
1818pub const sep_str = [1]u8{sep};
1919
2020pub const delimiter_windows = ';';
2121pub const delimiter_posix = ':';
22pub const delimiter = if (windows.is_the_target) delimiter_windows else delimiter_posix;
22pub const delimiter = if (builtin.os == .windows) delimiter_windows else delimiter_posix;
2323
2424pub fn isSep(byte: u8) bool {
25 if (windows.is_the_target) {
25 if (builtin.os == .windows) {
2626 return byte == '/' or byte == '\\';
2727 } else {
2828 return byte == '/';
......@@ -72,7 +72,7 @@ fn joinSep(allocator: *Allocator, separator: u8, paths: []const []const u8) ![]u
7272 return buf;
7373}
7474
75pub const join = if (windows.is_the_target) joinWindows else joinPosix;
75pub const join = if (builtin.os == .windows) joinWindows else joinPosix;
7676
7777/// Naively combines a series of paths with the native path seperator.
7878/// Allocates memory for the result, which must be freed by the caller.
......@@ -129,7 +129,7 @@ test "join" {
129129}
130130
131131pub fn isAbsolute(path: []const u8) bool {
132 if (windows.is_the_target) {
132 if (builtin.os == .windows) {
133133 return isAbsoluteWindows(path);
134134 } else {
135135 return isAbsolutePosix(path);
......@@ -327,7 +327,7 @@ test "windowsParsePath" {
327327}
328328
329329pub fn diskDesignator(path: []const u8) []const u8 {
330 if (windows.is_the_target) {
330 if (builtin.os == .windows) {
331331 return diskDesignatorWindows(path);
332332 } else {
333333 return "";
......@@ -392,7 +392,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool {
392392
393393/// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`.
394394pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {
395 if (windows.is_the_target) {
395 if (builtin.os == .windows) {
396396 return resolveWindows(allocator, paths);
397397 } else {
398398 return resolvePosix(allocator, paths);
......@@ -409,7 +409,7 @@ pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 {
409409/// Without performing actual syscalls, resolving `..` could be incorrect.
410410pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
411411 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
413413 return process.getCwdAlloc(allocator);
414414 }
415415
......@@ -504,7 +504,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
504504 result_disk_designator = result[0..result_index];
505505 },
506506 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
508508 const cwd = try process.getCwdAlloc(allocator);
509509 defer allocator.free(cwd);
510510 const parsed_cwd = windowsParsePath(cwd);
......@@ -519,7 +519,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
519519 },
520520 }
521521 } 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
523523 // TODO call get cwd for the result_disk_designator instead of the global one
524524 const cwd = try process.getCwdAlloc(allocator);
525525 defer allocator.free(cwd);
......@@ -590,7 +590,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
590590/// Without performing actual syscalls, resolving `..` could be incorrect.
591591pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
592592 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
594594 return process.getCwdAlloc(allocator);
595595 }
596596
......@@ -612,7 +612,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
612612 if (have_abs) {
613613 result = try allocator.alloc(u8, max_size);
614614 } 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
616616 const cwd = try process.getCwdAlloc(allocator);
617617 defer allocator.free(cwd);
618618 result = try allocator.alloc(u8, max_size + cwd.len + 1);
......@@ -653,7 +653,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
653653
654654test "resolve" {
655655 const cwd = try process.getCwdAlloc(debug.global_allocator);
656 if (windows.is_the_target) {
656 if (builtin.os == .windows) {
657657 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
658658 cwd[0] = asciiUpper(cwd[0]);
659659 }
......@@ -669,7 +669,7 @@ test "resolveWindows" {
669669 // TODO https://github.com/ziglang/zig/issues/3288
670670 return error.SkipZigTest;
671671 }
672 if (windows.is_the_target) {
672 if (builtin.os == .windows) {
673673 const cwd = try process.getCwdAlloc(debug.global_allocator);
674674 const parsed_cwd = windowsParsePath(cwd);
675675 {
......@@ -735,7 +735,7 @@ fn testResolvePosix(paths: []const []const u8) []u8 {
735735/// If the path is a file in the current directory (no directory component)
736736/// then returns null
737737pub fn dirname(path: []const u8) ?[]const u8 {
738 if (windows.is_the_target) {
738 if (builtin.os == .windows) {
739739 return dirnameWindows(path);
740740 } else {
741741 return dirnamePosix(path);
......@@ -867,7 +867,7 @@ fn testDirnameWindows(input: []const u8, expected_output: ?[]const u8) void {
867867}
868868
869869pub fn basename(path: []const u8) []const u8 {
870 if (windows.is_the_target) {
870 if (builtin.os == .windows) {
871871 return basenameWindows(path);
872872 } else {
873873 return basenamePosix(path);
......@@ -983,7 +983,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) void {
983983/// string is returned.
984984/// On Windows this canonicalizes the drive to a capital letter and paths to `\\`.
985985pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
986 if (windows.is_the_target) {
986 if (builtin.os == .windows) {
987987 return relativeWindows(allocator, from, to);
988988 } else {
989989 return relativePosix(allocator, from, to);
lib/std/heap.zig+3-3
......@@ -44,7 +44,7 @@ const DirectAllocator = struct {
4444 if (n == 0)
4545 return (([*]u8)(undefined))[0..0];
4646
47 if (os.windows.is_the_target) {
47 if (builtin.os == .windows) {
4848 const w = os.windows;
4949
5050 // Although officially it's at least aligned to page boundary,
......@@ -130,7 +130,7 @@ const DirectAllocator = struct {
130130
131131 fn shrink(allocator: *Allocator, old_mem_unaligned: []u8, old_align: u29, new_size: usize, new_align: u29) []u8 {
132132 const old_mem = @alignCast(mem.page_size, old_mem_unaligned);
133 if (os.windows.is_the_target) {
133 if (builtin.os == .windows) {
134134 const w = os.windows;
135135 if (new_size == 0) {
136136 // From the docs:
......@@ -170,7 +170,7 @@ const DirectAllocator = struct {
170170
171171 fn realloc(allocator: *Allocator, old_mem_unaligned: []u8, old_align: u29, new_size: usize, new_align: u29) ![]u8 {
172172 const old_mem = @alignCast(mem.page_size, old_mem_unaligned);
173 if (os.windows.is_the_target) {
173 if (builtin.os == .windows) {
174174 if (old_mem.len == 0) {
175175 return alloc(allocator, new_size, new_align);
176176 }
lib/std/io.zig+3-3
......@@ -37,7 +37,7 @@ pub const is_async = mode != .blocking;
3737pub const GetStdIoError = os.windows.GetStdHandleError;
3838
3939pub fn getStdOut() GetStdIoError!File {
40 if (os.windows.is_the_target) {
40 if (builtin.os == .windows) {
4141 const handle = try os.windows.GetStdHandle(os.windows.STD_OUTPUT_HANDLE);
4242 return File.openHandle(handle);
4343 }
......@@ -45,7 +45,7 @@ pub fn getStdOut() GetStdIoError!File {
4545}
4646
4747pub fn getStdErr() GetStdIoError!File {
48 if (os.windows.is_the_target) {
48 if (builtin.os == .windows) {
4949 const handle = try os.windows.GetStdHandle(os.windows.STD_ERROR_HANDLE);
5050 return File.openHandle(handle);
5151 }
......@@ -53,7 +53,7 @@ pub fn getStdErr() GetStdIoError!File {
5353}
5454
5555pub fn getStdIn() GetStdIoError!File {
56 if (os.windows.is_the_target) {
56 if (builtin.os == .windows) {
5757 const handle = try os.windows.GetStdHandle(os.windows.STD_INPUT_HANDLE);
5858 return File.openHandle(handle);
5959 }
lib/std/os.zig+64-61
......@@ -85,13 +85,13 @@ pub const errno = system.getErrno;
8585/// must call `fsync` before `close`.
8686/// Note: The Zig standard library does not support POSIX thread cancellation.
8787pub fn close(fd: fd_t) void {
88 if (windows.is_the_target) {
88 if (builtin.os == .windows) {
8989 return windows.CloseHandle(fd);
9090 }
91 if (wasi.is_the_target) {
91 if (builtin.os == .wasi) {
9292 _ = wasi.fd_close(fd);
9393 }
94 if (darwin.is_the_target) {
94 if (comptime std.Target.current.isDarwin()) {
9595 // This avoids the EINTR problem.
9696 switch (darwin.getErrno(darwin.@"close$NOCANCEL"(fd))) {
9797 EBADF => unreachable, // Always a race condition.
......@@ -113,12 +113,12 @@ pub const GetRandomError = OpenError;
113113/// appropriate OS-specific library call. Otherwise it uses the zig standard
114114/// library implementation.
115115pub fn getrandom(buffer: []u8) GetRandomError!void {
116 if (windows.is_the_target) {
116 if (builtin.os == .windows) {
117117 return windows.RtlGenRandom(buffer);
118118 }
119 if (linux.is_the_target or freebsd.is_the_target) {
119 if (builtin.os == .linux or builtin.os == .freebsd) {
120120 var buf = buffer;
121 const use_c = !linux.is_the_target or
121 const use_c = builtin.os != .linux or
122122 std.c.versionCheck(builtin.Version{ .major = 2, .minor = 25, .patch = 0 }).ok;
123123
124124 while (buf.len != 0) {
......@@ -145,7 +145,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
145145 }
146146 return;
147147 }
148 if (wasi.is_the_target) {
148 if (builtin.os == .wasi) {
149149 switch (wasi.random_get(buffer.ptr, buffer.len)) {
150150 0 => return,
151151 else => |err| return unexpectedErrno(err),
......@@ -175,7 +175,7 @@ pub fn abort() noreturn {
175175 // MSVCRT abort() sometimes opens a popup window which is undesirable, so
176176 // even when linking libc on Windows we use our own abort implementation.
177177 // See https://github.com/ziglang/zig/issues/2071 for more details.
178 if (windows.is_the_target) {
178 if (builtin.os == .windows) {
179179 if (builtin.mode == .Debug) {
180180 @breakpoint();
181181 }
......@@ -206,14 +206,14 @@ pub fn raise(sig: u8) RaiseError!void {
206206 }
207207 }
208208
209 if (wasi.is_the_target) {
209 if (builtin.os == .wasi) {
210210 switch (wasi.proc_raise(SIGABRT)) {
211211 0 => return,
212212 else => |err| return unexpectedErrno(err),
213213 }
214214 }
215215
216 if (linux.is_the_target) {
216 if (builtin.os == .linux) {
217217 var set: linux.sigset_t = undefined;
218218 linux.blockAppSignals(&set);
219219 const tid = linux.syscall0(linux.SYS_gettid);
......@@ -245,16 +245,16 @@ pub fn exit(status: u8) noreturn {
245245 if (builtin.link_libc) {
246246 system.exit(status);
247247 }
248 if (windows.is_the_target) {
248 if (builtin.os == .windows) {
249249 windows.kernel32.ExitProcess(status);
250250 }
251 if (wasi.is_the_target) {
251 if (builtin.os == .wasi) {
252252 wasi.proc_exit(status);
253253 }
254 if (linux.is_the_target and !builtin.single_threaded) {
254 if (builtin.os == .linux and !builtin.single_threaded) {
255255 linux.exit_group(status);
256256 }
257 if (uefi.is_the_target) {
257 if (builtin.os == .uefi) {
258258 // exit() is only avaliable if exitBootServices() has not been called yet.
259259 // This call to exit should not fail, so we don't care about its return value.
260260 if (uefi.system_table.boot_services) |bs| {
......@@ -283,11 +283,11 @@ pub const ReadError = error{
283283/// If the application has a global event loop enabled, EAGAIN is handled
284284/// via the event loop. Otherwise EAGAIN results in error.WouldBlock.
285285pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
286 if (windows.is_the_target) {
286 if (builtin.os == .windows) {
287287 return windows.ReadFile(fd, buf);
288288 }
289289
290 if (wasi.is_the_target and !builtin.link_libc) {
290 if (builtin.os == .wasi and !builtin.link_libc) {
291291 const iovs = [1]iovec{iovec{
292292 .iov_base = buf.ptr,
293293 .iov_len = buf.len,
......@@ -327,7 +327,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
327327/// Number of bytes read is returned. Upon reading end-of-file, zero is returned.
328328/// This function is for blocking file descriptors only.
329329pub 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()) {
331331 // Darwin does not have preadv but it does have pread.
332332 var off: usize = 0;
333333 var iov_i: usize = 0;
......@@ -398,11 +398,11 @@ pub const WriteError = error{
398398/// Write to a file descriptor. Keeps trying if it gets interrupted.
399399/// This function is for blocking file descriptors only.
400400pub fn write(fd: fd_t, bytes: []const u8) WriteError!void {
401 if (windows.is_the_target) {
401 if (builtin.os == .windows) {
402402 return windows.WriteFile(fd, bytes);
403403 }
404404
405 if (wasi.is_the_target and !builtin.link_libc) {
405 if (builtin.os == .wasi and !builtin.link_libc) {
406406 const ciovs = [1]iovec_const{iovec_const{
407407 .iov_base = bytes.ptr,
408408 .iov_len = bytes.len,
......@@ -477,7 +477,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!void {
477477/// This function is for blocking file descriptors only. For non-blocking, see
478478/// `pwritevAsync`.
479479pub 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()) {
481481 // Darwin does not have pwritev but it does have pwrite.
482482 var off: usize = 0;
483483 var iov_i: usize = 0;
......@@ -841,7 +841,7 @@ pub const GetCwdError = error{
841841
842842/// The result is a slice of out_buffer, indexed from 0.
843843pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
844 if (windows.is_the_target) {
844 if (builtin.os == .windows) {
845845 return windows.GetCurrentDirectory(out_buffer);
846846 }
847847
......@@ -882,7 +882,7 @@ pub const SymLinkError = error{
882882/// If `sym_link_path` exists, it will not be overwritten.
883883/// See also `symlinkC` and `symlinkW`.
884884pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError!void {
885 if (windows.is_the_target) {
885 if (builtin.os == .windows) {
886886 const target_path_w = try windows.sliceToPrefixedFileW(target_path);
887887 const sym_link_path_w = try windows.sliceToPrefixedFileW(sym_link_path);
888888 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!
896896/// This is the same as `symlink` except the parameters are null-terminated pointers.
897897/// See also `symlink`.
898898pub fn symlinkC(target_path: [*]const u8, sym_link_path: [*]const u8) SymLinkError!void {
899 if (windows.is_the_target) {
899 if (builtin.os == .windows) {
900900 const target_path_w = try windows.cStrToPrefixedFileW(target_path);
901901 const sym_link_path_w = try windows.cStrToPrefixedFileW(sym_link_path);
902902 return windows.CreateSymbolicLinkW(&sym_link_path_w, &target_path_w, 0);
......@@ -971,7 +971,7 @@ pub const UnlinkError = error{
971971/// Delete a name and possibly the file it refers to.
972972/// See also `unlinkC`.
973973pub fn unlink(file_path: []const u8) UnlinkError!void {
974 if (windows.is_the_target) {
974 if (builtin.os == .windows) {
975975 const file_path_w = try windows.sliceToPrefixedFileW(file_path);
976976 return windows.DeleteFileW(&file_path_w);
977977 } else {
......@@ -982,7 +982,7 @@ pub fn unlink(file_path: []const u8) UnlinkError!void {
982982
983983/// Same as `unlink` except the parameter is a null terminated UTF8-encoded string.
984984pub fn unlinkC(file_path: [*]const u8) UnlinkError!void {
985 if (windows.is_the_target) {
985 if (builtin.os == .windows) {
986986 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
987987 return windows.DeleteFileW(&file_path_w);
988988 }
......@@ -1012,7 +1012,7 @@ pub const UnlinkatError = UnlinkError || error{
10121012
10131013/// Delete a file name and possibly the file it refers to, based on an open directory handle.
10141014pub fn unlinkat(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!void {
1015 if (windows.is_the_target) {
1015 if (builtin.os == .windows) {
10161016 const file_path_w = try windows.sliceToPrefixedFileW(file_path);
10171017 return unlinkatW(dirfd, &file_path_w, flags);
10181018 }
......@@ -1022,7 +1022,7 @@ pub fn unlinkat(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!vo
10221022
10231023/// Same as `unlinkat` but `file_path` is a null-terminated string.
10241024pub 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) {
10261026 const file_path_w = try windows.cStrToPrefixedFileW(file_path_c);
10271027 return unlinkatW(dirfd, &file_path_w, flags);
10281028 }
......@@ -1133,7 +1133,7 @@ const RenameError = error{
11331133
11341134/// Change the name or location of a file.
11351135pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void {
1136 if (windows.is_the_target) {
1136 if (builtin.os == .windows) {
11371137 const old_path_w = try windows.sliceToPrefixedFileW(old_path);
11381138 const new_path_w = try windows.sliceToPrefixedFileW(new_path);
11391139 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 {
11461146
11471147/// Same as `rename` except the parameters are null-terminated byte arrays.
11481148pub fn renameC(old_path: [*]const u8, new_path: [*]const u8) RenameError!void {
1149 if (windows.is_the_target) {
1149 if (builtin.os == .windows) {
11501150 const old_path_w = try windows.cStrToPrefixedFileW(old_path);
11511151 const new_path_w = try windows.cStrToPrefixedFileW(new_path);
11521152 return renameW(&old_path_w, &new_path_w);
......@@ -1201,7 +1201,7 @@ pub const MakeDirError = error{
12011201/// Create a directory.
12021202/// `mode` is ignored on Windows.
12031203pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void {
1204 if (windows.is_the_target) {
1204 if (builtin.os == .windows) {
12051205 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);
12061206 return windows.CreateDirectoryW(&dir_path_w, null);
12071207 } else {
......@@ -1212,7 +1212,7 @@ pub fn mkdir(dir_path: []const u8, mode: u32) MakeDirError!void {
12121212
12131213/// Same as `mkdir` but the parameter is a null-terminated UTF8-encoded string.
12141214pub fn mkdirC(dir_path: [*]const u8, mode: u32) MakeDirError!void {
1215 if (windows.is_the_target) {
1215 if (builtin.os == .windows) {
12161216 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
12171217 return windows.CreateDirectoryW(&dir_path_w, null);
12181218 }
......@@ -1251,7 +1251,7 @@ pub const DeleteDirError = error{
12511251
12521252/// Deletes an empty directory.
12531253pub fn rmdir(dir_path: []const u8) DeleteDirError!void {
1254 if (windows.is_the_target) {
1254 if (builtin.os == .windows) {
12551255 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);
12561256 return windows.RemoveDirectoryW(&dir_path_w);
12571257 } else {
......@@ -1262,7 +1262,7 @@ pub fn rmdir(dir_path: []const u8) DeleteDirError!void {
12621262
12631263/// Same as `rmdir` except the parameter is null-terminated.
12641264pub fn rmdirC(dir_path: [*]const u8) DeleteDirError!void {
1265 if (windows.is_the_target) {
1265 if (builtin.os == .windows) {
12661266 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
12671267 return windows.RemoveDirectoryW(&dir_path_w);
12681268 }
......@@ -1298,7 +1298,7 @@ pub const ChangeCurDirError = error{
12981298/// Changes the current working directory of the calling process.
12991299/// `dir_path` is recommended to be a UTF-8 encoded string.
13001300pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
1301 if (windows.is_the_target) {
1301 if (builtin.os == .windows) {
13021302 const dir_path_w = try windows.sliceToPrefixedFileW(dir_path);
13031303 @compileError("TODO implement chdir for Windows");
13041304 } else {
......@@ -1309,7 +1309,7 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
13091309
13101310/// Same as `chdir` except the parameter is null-terminated.
13111311pub fn chdirC(dir_path: [*]const u8) ChangeCurDirError!void {
1312 if (windows.is_the_target) {
1312 if (builtin.os == .windows) {
13131313 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
13141314 @compileError("TODO implement chdir for Windows");
13151315 }
......@@ -1340,7 +1340,7 @@ pub const ReadLinkError = error{
13401340/// Read value of a symbolic link.
13411341/// The return value is a slice of `out_buffer` from index 0.
13421342pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
1343 if (windows.is_the_target) {
1343 if (builtin.os == .windows) {
13441344 const file_path_w = try windows.sliceToPrefixedFileW(file_path);
13451345 @compileError("TODO implement readlink for Windows");
13461346 } else {
......@@ -1351,7 +1351,7 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
13511351
13521352/// Same as `readlink` except `file_path` is null-terminated.
13531353pub fn readlinkC(file_path: [*]const u8, out_buffer: []u8) ReadLinkError![]u8 {
1354 if (windows.is_the_target) {
1354 if (builtin.os == .windows) {
13551355 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
13561356 @compileError("TODO implement readlink for Windows");
13571357 }
......@@ -1372,7 +1372,7 @@ pub fn readlinkC(file_path: [*]const u8, out_buffer: []u8) ReadLinkError![]u8 {
13721372}
13731373
13741374pub 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) {
13761376 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
13771377 @compileError("TODO implement readlink for Windows");
13781378 }
......@@ -1440,7 +1440,7 @@ pub fn setregid(rgid: u32, egid: u32) SetIdError!void {
14401440
14411441/// Test whether a file descriptor refers to a terminal.
14421442pub fn isatty(handle: fd_t) bool {
1443 if (windows.is_the_target) {
1443 if (builtin.os == .windows) {
14441444 if (isCygwinPty(handle))
14451445 return true;
14461446
......@@ -1450,10 +1450,10 @@ pub fn isatty(handle: fd_t) bool {
14501450 if (builtin.link_libc) {
14511451 return system.isatty(handle) != 0;
14521452 }
1453 if (wasi.is_the_target) {
1453 if (builtin.os == .wasi) {
14541454 @compileError("TODO implement std.os.isatty for WASI");
14551455 }
1456 if (linux.is_the_target) {
1456 if (builtin.os == .linux) {
14571457 var wsz: linux.winsize = undefined;
14581458 return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, isize(handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
14591459 }
......@@ -1461,7 +1461,7 @@ pub fn isatty(handle: fd_t) bool {
14611461}
14621462
14631463pub fn isCygwinPty(handle: fd_t) bool {
1464 if (!windows.is_the_target) return false;
1464 if (builtin.os != .windows) return false;
14651465
14661466 const size = @sizeOf(windows.FILE_NAME_INFO);
14671467 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;
19611961
19621962pub fn fstat(fd: fd_t) FStatError!Stat {
19631963 var stat: Stat = undefined;
1964 if (darwin.is_the_target) {
1964 if (comptime std.Target.current.isDarwin()) {
19651965 switch (darwin.getErrno(darwin.@"fstat$INODE64"(fd, &stat))) {
19661966 0 => return stat,
19671967 EINVAL => unreachable,
......@@ -2227,7 +2227,7 @@ pub const AccessError = error{
22272227/// check user's permissions for a file
22282228/// TODO currently this assumes `mode` is `F_OK` on Windows.
22292229pub fn access(path: []const u8, mode: u32) AccessError!void {
2230 if (windows.is_the_target) {
2230 if (builtin.os == .windows) {
22312231 const path_w = try windows.sliceToPrefixedFileW(path);
22322232 _ = try windows.GetFileAttributesW(&path_w);
22332233 return;
......@@ -2238,7 +2238,7 @@ pub fn access(path: []const u8, mode: u32) AccessError!void {
22382238
22392239/// Same as `access` except `path` is null-terminated.
22402240pub fn accessC(path: [*]const u8, mode: u32) AccessError!void {
2241 if (windows.is_the_target) {
2241 if (builtin.os == .windows) {
22422242 const path_w = try windows.cStrToPrefixedFileW(path);
22432243 _ = try windows.GetFileAttributesW(&path_w);
22442244 return;
......@@ -2358,7 +2358,7 @@ pub const SeekError = error{Unseekable} || UnexpectedError;
23582358
23592359/// Repositions read/write file offset relative to the beginning.
23602360pub 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) {
23622362 var result: u64 = undefined;
23632363 switch (errno(system.llseek(fd, offset, &result, SEEK_SET))) {
23642364 0 => return,
......@@ -2370,7 +2370,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
23702370 else => |err| return unexpectedErrno(err),
23712371 }
23722372 }
2373 if (windows.is_the_target) {
2373 if (builtin.os == .windows) {
23742374 return windows.SetFilePointerEx_BEGIN(fd, offset);
23752375 }
23762376 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 {
23872387
23882388/// Repositions read/write file offset relative to the current offset.
23892389pub 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) {
23912391 var result: u64 = undefined;
23922392 switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_CUR))) {
23932393 0 => return,
......@@ -2399,7 +2399,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
23992399 else => |err| return unexpectedErrno(err),
24002400 }
24012401 }
2402 if (windows.is_the_target) {
2402 if (builtin.os == .windows) {
24032403 return windows.SetFilePointerEx_CURRENT(fd, offset);
24042404 }
24052405 switch (errno(system.lseek(fd, offset, SEEK_CUR))) {
......@@ -2415,7 +2415,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
24152415
24162416/// Repositions read/write file offset relative to the end.
24172417pub 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) {
24192419 var result: u64 = undefined;
24202420 switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_END))) {
24212421 0 => return,
......@@ -2427,7 +2427,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
24272427 else => |err| return unexpectedErrno(err),
24282428 }
24292429 }
2430 if (windows.is_the_target) {
2430 if (builtin.os == .windows) {
24312431 return windows.SetFilePointerEx_END(fd, offset);
24322432 }
24332433 switch (errno(system.lseek(fd, offset, SEEK_END))) {
......@@ -2443,7 +2443,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
24432443
24442444/// Returns the read/write file offset relative to the beginning.
24452445pub 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) {
24472447 var result: u64 = undefined;
24482448 switch (errno(system.llseek(fd, 0, &result, SEEK_CUR))) {
24492449 0 => return result,
......@@ -2455,7 +2455,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
24552455 else => |err| return unexpectedErrno(err),
24562456 }
24572457 }
2458 if (windows.is_the_target) {
2458 if (builtin.os == .windows) {
24592459 return windows.SetFilePointerEx_CURRENT_get(fd);
24602460 }
24612461 const rc = system.lseek(fd, 0, SEEK_CUR);
......@@ -2504,7 +2504,7 @@ pub const RealPathError = error{
25042504/// The return value is a slice of `out_buffer`, but not necessarily from the beginning.
25052505/// See also `realpathC` and `realpathW`.
25062506pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
2507 if (windows.is_the_target) {
2507 if (builtin.os == .windows) {
25082508 const pathname_w = try windows.sliceToPrefixedFileW(pathname);
25092509 return realpathW(&pathname_w, out_buffer);
25102510 }
......@@ -2514,11 +2514,11 @@ pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathE
25142514
25152515/// Same as `realpath` except `pathname` is null-terminated.
25162516pub fn realpathC(pathname: [*]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
2517 if (windows.is_the_target) {
2517 if (builtin.os == .windows) {
25182518 const pathname_w = try windows.cStrToPrefixedFileW(pathname);
25192519 return realpathW(&pathname_w, out_buffer);
25202520 }
2521 if (linux.is_the_target and !builtin.link_libc) {
2521 if (builtin.os == .linux and !builtin.link_libc) {
25222522 const fd = try openC(pathname, linux.O_PATH | linux.O_NONBLOCK | linux.O_CLOEXEC, 0);
25232523 defer close(fd);
25242524
......@@ -2596,9 +2596,12 @@ pub fn nanosleep(seconds: u64, nanoseconds: u64) void {
25962596 }
25972597}
25982598
2599pub 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)
2599pub 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)
26022605 @compileError("dl_iterate_phdr is not available for this target");
26032606
26042607 if (builtin.link_libc) {
......@@ -2737,7 +2740,7 @@ pub const SigaltstackError = error{
27372740} || UnexpectedError;
27382741
27392742pub 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)
27412744 @compileError("std.os.sigaltstack not available for this target");
27422745
27432746 switch (errno(system.sigaltstack(ss, old_ss))) {
......@@ -2809,7 +2812,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
28092812 else => |err| return unexpectedErrno(err),
28102813 }
28112814 }
2812 if (linux.is_the_target) {
2815 if (builtin.os == .linux) {
28132816 var uts: utsname = undefined;
28142817 switch (errno(system.uname(&uts))) {
28152818 0 => {
lib/std/os/darwin.zig-4
......@@ -1,8 +1,4 @@
11const builtin = @import("builtin");
22const std = @import("../std.zig");
3pub const is_the_target = switch (builtin.os) {
4 .macosx, .tvos, .watchos, .ios => true,
5 else => false,
6};
73pub usingnamespace std.c;
84pub usingnamespace @import("bits.zig");
lib/std/os/freebsd.zig-2
......@@ -1,5 +1,3 @@
11const std = @import("../std.zig");
2const builtin = @import("builtin");
3pub const is_the_target = builtin.os == .freebsd;
42pub usingnamespace std.c;
53pub usingnamespace @import("bits.zig");
lib/std/os/linux.zig+1-2
......@@ -13,7 +13,6 @@ const elf = std.elf;
1313const vdso = @import("linux/vdso.zig");
1414const dl = @import("../dynamic_library.zig");
1515
16pub const is_the_target = builtin.os == .linux;
1716pub usingnamespace switch (builtin.arch) {
1817 .x86_64 => @import("linux/x86_64.zig"),
1918 .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
10791078}
10801079
10811080test "" {
1082 if (is_the_target) {
1081 if (builtin.os == .linux) {
10831082 _ = @import("linux/test.zig");
10841083 }
10851084}
lib/std/os/netbsd.zig-2
......@@ -1,5 +1,3 @@
1const builtin = @import("builtin");
21const std = @import("../std.zig");
3pub const is_the_target = builtin.os == .netbsd;
42pub usingnamespace std.c;
53pub usingnamespace @import("bits.zig");
lib/std/os/test.zig+3-3
......@@ -53,7 +53,7 @@ test "std.Thread.getCurrentId" {
5353 thread.wait();
5454 if (Thread.use_pthreads) {
5555 expect(thread_current_id == thread_id);
56 } else if (os.windows.is_the_target) {
56 } else if (builtin.os == .windows) {
5757 expect(Thread.getCurrentId() != thread_current_id);
5858 } else {
5959 // If the thread completes very quickly, then thread_id can be 0. See the
......@@ -212,7 +212,7 @@ test "dl_iterate_phdr" {
212212}
213213
214214test "gethostname" {
215 if (os.windows.is_the_target)
215 if (builtin.os == .windows)
216216 return error.SkipZigTest;
217217
218218 var buf: [os.HOST_NAME_MAX]u8 = undefined;
......@@ -221,7 +221,7 @@ test "gethostname" {
221221}
222222
223223test "pipe" {
224 if (os.windows.is_the_target)
224 if (builtin.os == .windows)
225225 return error.SkipZigTest;
226226
227227 var fds = try os.pipe();
lib/std/os/uefi.zig+13-3
......@@ -1,16 +1,15 @@
11/// A protocol is an interface identified by a GUID.
22pub const protocols = @import("uefi/protocols.zig");
3
34/// Status codes returned by EFI interfaces
45pub const status = @import("uefi/status.zig");
56pub const tables = @import("uefi/tables.zig");
67
78const fmt = @import("std").fmt;
89
9const builtin = @import("builtin");
10pub const is_the_target = builtin.os == .uefi;
11
1210/// The EFI image's handle that is passed to its entry point.
1311pub var handle: Handle = undefined;
12
1413/// A pointer to the EFI System Table that is passed to the EFI image's entry point.
1514pub var system_table: *tables.SystemTable = undefined;
1615
......@@ -50,26 +49,35 @@ pub const Handle = *@OpaqueType();
5049pub const Time = extern struct {
5150 /// 1900 - 9999
5251 year: u16,
52
5353 /// 1 - 12
5454 month: u8,
55
5556 /// 1 - 31
5657 day: u8,
58
5759 /// 0 - 23
5860 hour: u8,
61
5962 /// 0 - 59
6063 minute: u8,
64
6165 /// 0 - 59
6266 second: u8,
6367 _pad1: u8,
68
6469 /// 0 - 999999999
6570 nanosecond: u32,
71
6672 /// The time's offset in minutes from UTC.
6773 /// Allowed values are -1440 to 1440 or unspecified_timezone
6874 timezone: i16,
6975 daylight: packed struct {
7076 _pad1: u6,
77
7178 /// If true, the time has been adjusted for daylight savings time.
7279 in_daylight: bool,
80
7381 /// If true, the time is affected by daylight savings time.
7482 adjust_daylight: bool,
7583 },
......@@ -83,8 +91,10 @@ pub const Time = extern struct {
8391pub const TimeCapabilities = extern struct {
8492 /// Resolution in Hz
8593 resolution: u32,
94
8695 /// Accuracy in an error rate of 1e-6 parts per million.
8796 accuracy: u32,
97
8898 /// If true, a time set operation clears the device's time below the resolution level.
8999 sets_to_zero: bool,
90100};
lib/std/os/wasi.zig-2
......@@ -1,10 +1,8 @@
11// Based on https://github.com/CraneStation/wasi-sysroot/blob/wasi/libc-bottom-half/headers/public/wasi/core.h
22// and https://github.com/WebAssembly/WASI/blob/master/design/WASI-core.md
3const builtin = @import("builtin");
43const std = @import("std");
54const assert = std.debug.assert;
65
7pub const is_the_target = builtin.os == .wasi;
86pub usingnamespace @import("bits.zig");
97
108comptime {
lib/std/os/windows.zig-1
......@@ -11,7 +11,6 @@ const assert = std.debug.assert;
1111const math = std.math;
1212const maxInt = std.math.maxInt;
1313
14pub const is_the_target = builtin.os == .windows;
1514pub const advapi32 = @import("windows/advapi32.zig");
1615pub const kernel32 = @import("windows/kernel32.zig");
1716pub const ntdll = @import("windows/ntdll.zig");
lib/std/process.zig+2-2
......@@ -39,7 +39,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
3939 var result = BufMap.init(allocator);
4040 errdefer result.deinit();
4141
42 if (os.windows.is_the_target) {
42 if (builtin.os == .windows) {
4343 const ptr = try os.windows.GetEnvironmentStringsW();
4444 defer os.windows.FreeEnvironmentStringsW(ptr);
4545
......@@ -129,7 +129,7 @@ pub const GetEnvVarOwnedError = error{
129129/// Caller must free returned memory.
130130/// TODO make this go through libc when we have it
131131pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwnedError![]u8 {
132 if (os.windows.is_the_target) {
132 if (builtin.os == .windows) {
133133 const key_with_null = try std.unicode.utf8ToUtf16LeWithNull(allocator, key);
134134 defer allocator.free(key_with_null);
135135
lib/std/target.zig+3
......@@ -1,6 +1,9 @@
11const std = @import("std.zig");
22const builtin = std.builtin;
33
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.
47pub const Target = union(enum) {
58 Native: void,
69 Cross: Cross,
lib/std/thread.zig+5-5
......@@ -9,7 +9,7 @@ const assert = std.debug.assert;
99pub const Thread = struct {
1010 data: Data,
1111
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;
1313
1414 /// Represents a kernel thread handle.
1515 /// May be an integer or a pointer depending on the platform.
......@@ -309,7 +309,7 @@ pub const Thread = struct {
309309 os.EINVAL => unreachable,
310310 else => return os.unexpectedErrno(@intCast(usize, err)),
311311 }
312 } else if (os.linux.is_the_target) {
312 } else if (builtin.os == .linux) {
313313 var flags: u32 = os.CLONE_VM | os.CLONE_FS | os.CLONE_FILES | os.CLONE_SIGHAND |
314314 os.CLONE_THREAD | os.CLONE_SYSVSEM | os.CLONE_PARENT_SETTID | os.CLONE_CHILD_CLEARTID |
315315 os.CLONE_DETACHED;
......@@ -342,18 +342,18 @@ pub const Thread = struct {
342342 };
343343
344344 pub fn cpuCount() CpuCountError!usize {
345 if (os.linux.is_the_target) {
345 if (builtin.os == .linux) {
346346 const cpu_set = try os.sched_getaffinity(0);
347347 return usize(os.CPU_COUNT(cpu_set)); // TODO should not need this usize cast
348348 }
349 if (os.windows.is_the_target) {
349 if (builtin.os == .windows) {
350350 var system_info: windows.SYSTEM_INFO = undefined;
351351 windows.kernel32.GetSystemInfo(&system_info);
352352 return @intCast(usize, system_info.dwNumberOfProcessors);
353353 }
354354 var count: c_int = undefined;
355355 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";
357357 os.sysctlbynameC(name, &count, &count_len, null, 0) catch |err| switch (err) {
358358 error.NameTooLong => unreachable,
359359 else => |e| return e,
lib/std/time.zig+10-10
......@@ -9,7 +9,7 @@ pub const epoch = @import("time/epoch.zig");
99
1010/// Spurious wakeups are possible and no precision of timing is guaranteed.
1111pub fn sleep(nanoseconds: u64) void {
12 if (os.windows.is_the_target) {
12 if (builtin.os == .windows) {
1313 const ns_per_ms = ns_per_s / ms_per_s;
1414 const big_ms_from_ns = nanoseconds / ns_per_ms;
1515 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 {
3030/// Get the posix timestamp, UTC, in milliseconds
3131/// TODO audit this function. is it possible to return an error?
3232pub fn milliTimestamp() u64 {
33 if (os.windows.is_the_target) {
33 if (builtin.os == .windows) {
3434 //FileTime has a granularity of 100 nanoseconds
3535 // and uses the NTFS/Windows epoch
3636 var ft: os.windows.FILETIME = undefined;
......@@ -41,7 +41,7 @@ pub fn milliTimestamp() u64 {
4141 const ft64 = (u64(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
4242 return @divFloor(ft64, hns_per_ms) - -epoch_adj;
4343 }
44 if (os.wasi.is_the_target and !builtin.link_libc) {
44 if (builtin.os == .wasi and !builtin.link_libc) {
4545 var ns: os.wasi.timestamp_t = undefined;
4646
4747 // TODO: Verify that precision is ignored
......@@ -51,7 +51,7 @@ pub fn milliTimestamp() u64 {
5151 const ns_per_ms = 1000;
5252 return @divFloor(ns, ns_per_ms);
5353 }
54 if (os.darwin.is_the_target) {
54 if (comptime std.Target.current.isDarwin()) {
5555 var tv: os.darwin.timeval = undefined;
5656 var err = os.darwin.gettimeofday(&tv, null);
5757 assert(err == 0);
......@@ -126,11 +126,11 @@ pub const Timer = struct {
126126 pub fn start() Error!Timer {
127127 var self: Timer = undefined;
128128
129 if (os.windows.is_the_target) {
129 if (builtin.os == .windows) {
130130 self.frequency = os.windows.QueryPerformanceFrequency();
131131 self.resolution = @divFloor(ns_per_s, self.frequency);
132132 self.start_time = os.windows.QueryPerformanceCounter();
133 } else if (os.darwin.is_the_target) {
133 } else if (comptime std.Target.current.isDarwin()) {
134134 os.darwin.mach_timebase_info(&self.frequency);
135135 self.resolution = @divFloor(self.frequency.numer, self.frequency.denom);
136136 self.start_time = os.darwin.mach_absolute_time();
......@@ -154,10 +154,10 @@ pub const Timer = struct {
154154 /// Reads the timer value since start or the last reset in nanoseconds
155155 pub fn read(self: *Timer) u64 {
156156 var clock = clockNative() - self.start_time;
157 if (os.windows.is_the_target) {
157 if (builtin.os == .windows) {
158158 return @divFloor(clock * ns_per_s, self.frequency);
159159 }
160 if (os.darwin.is_the_target) {
160 if (comptime std.Target.current.isDarwin()) {
161161 return @divFloor(clock * self.frequency.numer, self.frequency.denom);
162162 }
163163 return clock;
......@@ -177,10 +177,10 @@ pub const Timer = struct {
177177 }
178178
179179 fn clockNative() u64 {
180 if (os.windows.is_the_target) {
180 if (builtin.os == .windows) {
181181 return os.windows.QueryPerformanceCounter();
182182 }
183 if (os.darwin.is_the_target) {
183 if (comptime std.Target.current.isDarwin()) {
184184 return os.darwin.mach_absolute_time();
185185 }
186186 var ts: os.timespec = undefined;