From 1829580631a6eb1746831f59e1254cef7d9573ac Mon Sep 17 00:00:00 2001 From: Precious Aleaji Date: Fri, 27 Feb 2026 06:12:32 +0100 Subject: [PATCH 1/2] replace getStdOut() with OS write syscalls --- .../02-emitting-an-executable.md | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/website/versioned_docs/version-0.15.x/03-build-system/02-emitting-an-executable.md b/website/versioned_docs/version-0.15.x/03-build-system/02-emitting-an-executable.md index 2064700f..46918ed7 100644 --- a/website/versioned_docs/version-0.15.x/03-build-system/02-emitting-an-executable.md +++ b/website/versioned_docs/version-0.15.x/03-build-system/02-emitting-an-executable.md @@ -15,12 +15,28 @@ Some common arguments: Let's create a tiny hello world. Save this as `tiny-hello.zig`, and run `zig build-exe tiny-hello.zig -O ReleaseSmall -fstrip -fsingle-threaded`. +We'll print "Hello World" using Zig's wrappers around the OS write syscall + +Linux: + +```zig +const std = @import("std"); + +pub fn main() void { + const msg = "Hello World\n"; + _ = std.os.linux.write(1, msg, msg.len); +} + +``` + +Windows: + ```zig const std = @import("std"); pub fn main() void { - std.io.getStdOut().writeAll( - "Hello World!", - ) catch unreachable; + const msg = "Hello World\n"; + const handle = std.os.windows.GetStdHandle(std.os.windows.STD_OUTPUT_HANDLE) catch return; + _ = std.os.windows.WriteFile(handle, msg, null, null) catch return; } ``` From 4ae8385b752c6ef46847349bdc092aec21fe25e9 Mon Sep 17 00:00:00 2001 From: Precious Aleaji Date: Fri, 27 Feb 2026 06:47:34 +0100 Subject: [PATCH 2/2] fix duplicate null --- .../version-0.15.x/03-build-system/02-emitting-an-executable.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/versioned_docs/version-0.15.x/03-build-system/02-emitting-an-executable.md b/website/versioned_docs/version-0.15.x/03-build-system/02-emitting-an-executable.md index 46918ed7..690ced36 100644 --- a/website/versioned_docs/version-0.15.x/03-build-system/02-emitting-an-executable.md +++ b/website/versioned_docs/version-0.15.x/03-build-system/02-emitting-an-executable.md @@ -37,6 +37,6 @@ const std = @import("std"); pub fn main() void { const msg = "Hello World\n"; const handle = std.os.windows.GetStdHandle(std.os.windows.STD_OUTPUT_HANDLE) catch return; - _ = std.os.windows.WriteFile(handle, msg, null, null) catch return; + _ = std.os.windows.WriteFile(handle, msg, null) catch return; } ```