From 5de07ab721380c39130a0bd3277a272673e3d644 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 27 May 2019 15:48:31 -0400 Subject: [PATCH] revert hello world examples. macos tests passing --- example/hello_world/hello.zig | 8 ++++++-- example/hello_world/hello_libc.zig | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/example/hello_world/hello.zig b/example/hello_world/hello.zig index 126faf62fb..cb7d5ef157 100644 --- a/example/hello_world/hello.zig +++ b/example/hello_world/hello.zig @@ -1,5 +1,9 @@ const std = @import("std"); -pub fn main() void { - std.debug.warn("Hello, world!\n"); +pub fn main() !void { + // If this program is run without stdout attached, exit with an error. + const stdout_file = try std.io.getStdOut(); + // If this program encounters pipe failure when printing to stdout, exit + // with an error. + try stdout_file.write("Hello, world!\n"); } diff --git a/example/hello_world/hello_libc.zig b/example/hello_world/hello_libc.zig index d18b1c26b3..05356bf529 100644 --- a/example/hello_world/hello_libc.zig +++ b/example/hello_world/hello_libc.zig @@ -2,9 +2,12 @@ const c = @cImport({ // See https://github.com/ziglang/zig/issues/515 @cDefine("_NO_CRT_STDIO_INLINE", "1"); @cInclude("stdio.h"); + @cInclude("string.h"); }); -export fn main(argc: c_int, argv: [*]?[*]u8) c_int { - _ = c.fprintf(c.stderr, c"Hello, world!\n"); +const msg = c"Hello, world!\n"; + +export fn main(argc: c_int, argv: **u8) c_int { + if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1; return 0; }