authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-05 14:08:56-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-05 14:08:56-04:00
log3ad9349f09e5afdacd64b8ab257ae1d09859f48a
tree429dd87dbdbfb8935dfc70b7b37e69b7dea10279
parent0d84d52e37923aab3c7f44b20b1490d6c0fbaac5
signaturelock-open Commit is signed but in an unrecognized format.

add std.os.windows.subsystem

The original issue that #2445 wanted to fix was solved in the previous commit. However it also exposed the subsystem in the standard library, which is still useful. So that's done in this commit, and #2445 can be closed.

1 files changed, 27 insertions(+), 0 deletions(-)

std/os/windows.zig+27
......@@ -20,6 +20,33 @@ pub const shell32 = @import("windows/shell32.zig");
2020
2121pub usingnamespace @import("windows/bits.zig");
2222
23/// `builtin` is missing `subsystem` when the subsystem is automatically detected,
24/// so Zig standard library has the subsystem detection logic here. This should generally be
25/// used rather than `builtin.subsystem`.
26/// On non-windows targets, this is `null`.
27pub const subsystem: ?builtin.SubSystem = blk: {
28 if (@hasDecl(builtin, "subsystem")) break :blk builtin.subsystem;
29 switch (builtin.os) {
30 .windows => {
31 if (builtin.is_test) {
32 break :blk builtin.SubSystem.Console;
33 }
34 const root = @import("root");
35 if (@hasDecl(root, "WinMain") or
36 @hasDecl(root, "wWinMain") or
37 @hasDecl(root, "WinMainCRTStartup") or
38 @hasDecl(root, "wWinMainCRTStartup"))
39 {
40 break :blk builtin.SubSystem.Windows;
41 } else {
42 break :blk builtin.SubSystem.Console;
43 }
44 },
45 .uefi => break :blk builtin.SubSystem.EfiApplication,
46 else => break :blk null,
47 }
48};
49
2350pub const CreateFileError = error{
2451 SharingViolation,
2552 PathAlreadyExists,