| author | |
| committer | |
| log | 0237e7a701892a0bf3c57e6868f54421782ff91d |
| tree | 0dacfcaf38543d384656b86ce846a3065a0ca1e3 |
| parent | 8bae70454dabe77dfe7e5344e59ca2180d63af51 |
Thanks to the Windows Process Environment Block, it is possible to
obtain handles to the standard input, output, and error streams without
possibility of failure.17 files changed, 76 insertions(+), 115 deletions(-)
doc/langref.html.in+2-5| ... | ... | @@ -202,11 +202,8 @@ |
| 202 | 202 | const std = @import("std"); |
| 203 | 203 | |
| 204 | 204 | pub fn main() !void { |
| 205 | // If this program is run without stdout attached, exit with an error. | |
| 206 | const stdout_file = try std.io.getStdOut(); | |
| 207 | // If this program encounters pipe failure when printing to stdout, exit | |
| 208 | // with an error. | |
| 209 | try stdout_file.write("Hello, world!\n"); | |
| 205 | const stdout = &std.io.getStdOut().outStream().stream; | |
| 206 | try stdout.print("Hello, {}!\n", "world"); | |
| 210 | 207 | } |
| 211 | 208 | {#code_end#} |
| 212 | 209 | <p> |
lib/std/crypto/benchmark.zig+1-3| ... | ... | @@ -131,9 +131,7 @@ fn printPad(stdout: var, s: []const u8) !void { |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | pub fn main() !void { |
| 134 | var stdout_file = try std.io.getStdOut(); | |
| 135 | var stdout_out_stream = stdout_file.outStream(); | |
| 136 | const stdout = &stdout_out_stream.stream; | |
| 134 | const stdout = &std.io.getStdOut().outStream().stream; | |
| 137 | 135 | |
| 138 | 136 | var buffer: [1024]u8 = undefined; |
| 139 | 137 | var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]); |
lib/std/debug.zig+7-7| ... | ... | @@ -49,15 +49,15 @@ var stderr_mutex = std.Mutex.init(); |
| 49 | 49 | pub fn warn(comptime fmt: []const u8, args: ...) void { |
| 50 | 50 | const held = stderr_mutex.acquire(); |
| 51 | 51 | defer held.release(); |
| 52 | const stderr = getStderrStream() catch return; | |
| 52 | const stderr = getStderrStream(); | |
| 53 | 53 | stderr.print(fmt, args) catch return; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | pub fn getStderrStream() !*io.OutStream(File.WriteError) { | |
| 56 | pub fn getStderrStream() *io.OutStream(File.WriteError) { | |
| 57 | 57 | if (stderr_stream) |st| { |
| 58 | 58 | return st; |
| 59 | 59 | } else { |
| 60 | stderr_file = try io.getStdErr(); | |
| 60 | stderr_file = io.getStdErr(); | |
| 61 | 61 | stderr_file_out_stream = stderr_file.outStream(); |
| 62 | 62 | const st = &stderr_file_out_stream.stream; |
| 63 | 63 | stderr_stream = st; |
| ... | ... | @@ -90,7 +90,7 @@ fn wantTtyColor() bool { |
| 90 | 90 | /// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned. |
| 91 | 91 | /// TODO multithreaded awareness |
| 92 | 92 | pub fn dumpCurrentStackTrace(start_addr: ?usize) void { |
| 93 | const stderr = getStderrStream() catch return; | |
| 93 | const stderr = getStderrStream(); | |
| 94 | 94 | if (builtin.strip_debug_info) { |
| 95 | 95 | stderr.print("Unable to dump stack trace: debug info stripped\n") catch return; |
| 96 | 96 | return; |
| ... | ... | @@ -109,7 +109,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void { |
| 109 | 109 | /// unbuffered, and ignores any error returned. |
| 110 | 110 | /// TODO multithreaded awareness |
| 111 | 111 | pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void { |
| 112 | const stderr = getStderrStream() catch return; | |
| 112 | const stderr = getStderrStream(); | |
| 113 | 113 | if (builtin.strip_debug_info) { |
| 114 | 114 | stderr.print("Unable to dump stack trace: debug info stripped\n") catch return; |
| 115 | 115 | return; |
| ... | ... | @@ -182,7 +182,7 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace |
| 182 | 182 | /// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned. |
| 183 | 183 | /// TODO multithreaded awareness |
| 184 | 184 | pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void { |
| 185 | const stderr = getStderrStream() catch return; | |
| 185 | const stderr = getStderrStream(); | |
| 186 | 186 | if (builtin.strip_debug_info) { |
| 187 | 187 | stderr.print("Unable to dump stack trace: debug info stripped\n") catch return; |
| 188 | 188 | return; |
| ... | ... | @@ -237,7 +237,7 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c |
| 237 | 237 | // which first called panic can finish printing a stack trace. |
| 238 | 238 | os.abort(); |
| 239 | 239 | } |
| 240 | const stderr = getStderrStream() catch os.abort(); | |
| 240 | const stderr = getStderrStream(); | |
| 241 | 241 | stderr.print(format ++ "\n", args) catch os.abort(); |
| 242 | 242 | if (trace) |t| { |
| 243 | 243 | dumpStackTrace(t.*); |
lib/std/io.zig+9-16| ... | ... | @@ -34,28 +34,23 @@ else |
| 34 | 34 | Mode.blocking; |
| 35 | 35 | pub const is_async = mode != .blocking; |
| 36 | 36 | |
| 37 | pub const GetStdIoError = os.windows.GetStdHandleError; | |
| 38 | ||
| 39 | pub fn getStdOut() GetStdIoError!File { | |
| 37 | pub fn getStdOut() File { | |
| 40 | 38 | if (builtin.os == .windows) { |
| 41 | const handle = try os.windows.GetStdHandle(os.windows.STD_OUTPUT_HANDLE); | |
| 42 | return File.openHandle(handle); | |
| 39 | return File.openHandle(os.windows.peb().ProcessParameters.hStdOutput); | |
| 43 | 40 | } |
| 44 | 41 | return File.openHandle(os.STDOUT_FILENO); |
| 45 | 42 | } |
| 46 | 43 | |
| 47 | pub fn getStdErr() GetStdIoError!File { | |
| 44 | pub fn getStdErr() File { | |
| 48 | 45 | if (builtin.os == .windows) { |
| 49 | const handle = try os.windows.GetStdHandle(os.windows.STD_ERROR_HANDLE); | |
| 50 | return File.openHandle(handle); | |
| 46 | return File.openHandle(os.windows.peb().ProcessParameters.hStdError); | |
| 51 | 47 | } |
| 52 | 48 | return File.openHandle(os.STDERR_FILENO); |
| 53 | 49 | } |
| 54 | 50 | |
| 55 | pub fn getStdIn() GetStdIoError!File { | |
| 51 | pub fn getStdIn() File { | |
| 56 | 52 | if (builtin.os == .windows) { |
| 57 | const handle = try os.windows.GetStdHandle(os.windows.STD_INPUT_HANDLE); | |
| 58 | return File.openHandle(handle); | |
| 53 | return File.openHandle(os.windows.peb().ProcessParameters.hStdInput); | |
| 59 | 54 | } |
| 60 | 55 | return File.openHandle(os.STDIN_FILENO); |
| 61 | 56 | } |
| ... | ... | @@ -598,7 +593,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr |
| 598 | 593 | self.index = 0; |
| 599 | 594 | } |
| 600 | 595 | |
| 601 | fn writeFn(out_stream: *Stream, bytes: []const u8) !void { | |
| 596 | fn writeFn(out_stream: *Stream, bytes: []const u8) Error!void { | |
| 602 | 597 | const self = @fieldParentPtr(Self, "stream", out_stream); |
| 603 | 598 | |
| 604 | 599 | if (bytes.len >= self.buffer.len) { |
| ... | ... | @@ -814,8 +809,7 @@ pub const BufferedAtomicFile = struct { |
| 814 | 809 | }; |
| 815 | 810 | |
| 816 | 811 | pub fn readLine(buf: *std.Buffer) ![]u8 { |
| 817 | var stdin = try getStdIn(); | |
| 818 | var stdin_stream = stdin.inStream(); | |
| 812 | var stdin_stream = getStdIn().inStream(); | |
| 819 | 813 | return readLineFrom(&stdin_stream.stream, buf); |
| 820 | 814 | } |
| 821 | 815 | |
| ... | ... | @@ -856,8 +850,7 @@ test "io.readLineFrom" { |
| 856 | 850 | } |
| 857 | 851 | |
| 858 | 852 | pub fn readLineSlice(slice: []u8) ![]u8 { |
| 859 | var stdin = try getStdIn(); | |
| 860 | var stdin_stream = stdin.inStream(); | |
| 853 | var stdin_stream = getStdIn().inStream(); | |
| 861 | 854 | return readLineSliceFrom(&stdin_stream.stream, slice); |
| 862 | 855 | } |
| 863 | 856 |
lib/std/json.zig+2-2| ... | ... | @@ -1015,7 +1015,7 @@ pub const Value = union(enum) { |
| 1015 | 1015 | var held = std.debug.getStderrMutex().acquire(); |
| 1016 | 1016 | defer held.release(); |
| 1017 | 1017 | |
| 1018 | const stderr = std.debug.getStderrStream() catch return; | |
| 1018 | const stderr = std.debug.getStderrStream(); | |
| 1019 | 1019 | self.dumpStream(stderr, 1024) catch return; |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| ... | ... | @@ -1026,7 +1026,7 @@ pub const Value = union(enum) { |
| 1026 | 1026 | var held = std.debug.getStderrMutex().acquire(); |
| 1027 | 1027 | defer held.release(); |
| 1028 | 1028 | |
| 1029 | const stderr = std.debug.getStderrStream() catch return; | |
| 1029 | const stderr = std.debug.getStderrStream(); | |
| 1030 | 1030 | self.dumpStreamIndent(indent, stderr, 1024) catch return; |
| 1031 | 1031 | } |
| 1032 | 1032 | } |
lib/std/progress.zig+2-5| ... | ... | @@ -98,11 +98,8 @@ pub const Progress = struct { |
| 98 | 98 | /// TODO solve https://github.com/ziglang/zig/issues/2765 and then change this |
| 99 | 99 | /// API to return Progress rather than accept it as a parameter. |
| 100 | 100 | pub fn start(self: *Progress, name: []const u8, estimated_total_items: ?usize) !*Node { |
| 101 | if (std.io.getStdErr()) |stderr| { | |
| 102 | self.terminal = if (stderr.supportsAnsiEscapeCodes()) stderr else null; | |
| 103 | } else |_| { | |
| 104 | self.terminal = null; | |
| 105 | } | |
| 101 | const stderr = std.io.getStdErr(); | |
| 102 | self.terminal = if (stderr.supportsAnsiEscapeCodes()) stderr else null; | |
| 106 | 103 | self.root = Node{ |
| 107 | 104 | .context = self, |
| 108 | 105 | .parent = null, |
lib/std/special/build_runner.zig+12-23| ... | ... | @@ -43,19 +43,8 @@ pub fn main() !void { |
| 43 | 43 | |
| 44 | 44 | var targets = ArrayList([]const u8).init(allocator); |
| 45 | 45 | |
| 46 | var stderr_file = io.getStdErr(); | |
| 47 | var stderr_file_stream: File.OutStream = undefined; | |
| 48 | var stderr_stream = if (stderr_file) |f| x: { | |
| 49 | stderr_file_stream = f.outStream(); | |
| 50 | break :x &stderr_file_stream.stream; | |
| 51 | } else |err| err; | |
| 52 | ||
| 53 | var stdout_file = io.getStdOut(); | |
| 54 | var stdout_file_stream: File.OutStream = undefined; | |
| 55 | var stdout_stream = if (stdout_file) |f| x: { | |
| 56 | stdout_file_stream = f.outStream(); | |
| 57 | break :x &stdout_file_stream.stream; | |
| 58 | } else |err| err; | |
| 46 | const stderr_stream = &io.getStdErr().outStream().stream; | |
| 47 | const stdout_stream = &io.getStdOut().outStream().stream; | |
| 59 | 48 | |
| 60 | 49 | while (arg_it.next(allocator)) |err_or_arg| { |
| 61 | 50 | const arg = try unwrapArg(err_or_arg); |
| ... | ... | @@ -63,37 +52,37 @@ pub fn main() !void { |
| 63 | 52 | const option_contents = arg[2..]; |
| 64 | 53 | if (option_contents.len == 0) { |
| 65 | 54 | warn("Expected option name after '-D'\n\n"); |
| 66 | return usageAndErr(builder, false, try stderr_stream); | |
| 55 | return usageAndErr(builder, false, stderr_stream); | |
| 67 | 56 | } |
| 68 | 57 | if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| { |
| 69 | 58 | const option_name = option_contents[0..name_end]; |
| 70 | 59 | const option_value = option_contents[name_end + 1 ..]; |
| 71 | 60 | if (try builder.addUserInputOption(option_name, option_value)) |
| 72 | return usageAndErr(builder, false, try stderr_stream); | |
| 61 | return usageAndErr(builder, false, stderr_stream); | |
| 73 | 62 | } else { |
| 74 | 63 | if (try builder.addUserInputFlag(option_contents)) |
| 75 | return usageAndErr(builder, false, try stderr_stream); | |
| 64 | return usageAndErr(builder, false, stderr_stream); | |
| 76 | 65 | } |
| 77 | 66 | } else if (mem.startsWith(u8, arg, "-")) { |
| 78 | 67 | if (mem.eql(u8, arg, "--verbose")) { |
| 79 | 68 | builder.verbose = true; |
| 80 | 69 | } else if (mem.eql(u8, arg, "--help")) { |
| 81 | return usage(builder, false, try stdout_stream); | |
| 70 | return usage(builder, false, stdout_stream); | |
| 82 | 71 | } else if (mem.eql(u8, arg, "--prefix")) { |
| 83 | 72 | builder.install_prefix = try unwrapArg(arg_it.next(allocator) orelse { |
| 84 | 73 | warn("Expected argument after --prefix\n\n"); |
| 85 | return usageAndErr(builder, false, try stderr_stream); | |
| 74 | return usageAndErr(builder, false, stderr_stream); | |
| 86 | 75 | }); |
| 87 | 76 | } else if (mem.eql(u8, arg, "--search-prefix")) { |
| 88 | 77 | const search_prefix = try unwrapArg(arg_it.next(allocator) orelse { |
| 89 | 78 | warn("Expected argument after --search-prefix\n\n"); |
| 90 | return usageAndErr(builder, false, try stderr_stream); | |
| 79 | return usageAndErr(builder, false, stderr_stream); | |
| 91 | 80 | }); |
| 92 | 81 | builder.addSearchPrefix(search_prefix); |
| 93 | 82 | } else if (mem.eql(u8, arg, "--override-lib-dir")) { |
| 94 | 83 | builder.override_lib_dir = try unwrapArg(arg_it.next(allocator) orelse { |
| 95 | 84 | warn("Expected argument after --override-lib-dir\n\n"); |
| 96 | return usageAndErr(builder, false, try stderr_stream); | |
| 85 | return usageAndErr(builder, false, stderr_stream); | |
| 97 | 86 | }); |
| 98 | 87 | } else if (mem.eql(u8, arg, "--verbose-tokenize")) { |
| 99 | 88 | builder.verbose_tokenize = true; |
| ... | ... | @@ -111,7 +100,7 @@ pub fn main() !void { |
| 111 | 100 | builder.verbose_cc = true; |
| 112 | 101 | } else { |
| 113 | 102 | warn("Unrecognized argument: {}\n\n", arg); |
| 114 | return usageAndErr(builder, false, try stderr_stream); | |
| 103 | return usageAndErr(builder, false, stderr_stream); | |
| 115 | 104 | } |
| 116 | 105 | } else { |
| 117 | 106 | try targets.append(arg); |
| ... | ... | @@ -122,12 +111,12 @@ pub fn main() !void { |
| 122 | 111 | try runBuild(builder); |
| 123 | 112 | |
| 124 | 113 | if (builder.validateUserInputDidItFail()) |
| 125 | return usageAndErr(builder, true, try stderr_stream); | |
| 114 | return usageAndErr(builder, true, stderr_stream); | |
| 126 | 115 | |
| 127 | 116 | builder.make(targets.toSliceConst()) catch |err| { |
| 128 | 117 | switch (err) { |
| 129 | 118 | error.InvalidStepName => { |
| 130 | return usageAndErr(builder, true, try stderr_stream); | |
| 119 | return usageAndErr(builder, true, stderr_stream); | |
| 131 | 120 | }, |
| 132 | 121 | error.UncleanExit => process.exit(1), |
| 133 | 122 | else => return err, |
lib/std/unicode/throughput_test.zig+1-3| ... | ... | @@ -2,9 +2,7 @@ const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | |
| 4 | 4 | pub fn main() !void { |
| 5 | var stdout_file = try std.io.getStdOut(); | |
| 6 | var stdout_out_stream = stdout_file.outStream(); | |
| 7 | const stdout = &stdout_out_stream.stream; | |
| 5 | const stdout = &std.io.getStdOut().outStream().stream; | |
| 8 | 6 | |
| 9 | 7 | const args = try std.process.argsAlloc(std.heap.direct_allocator); |
| 10 | 8 |
lib/std/zig/parser_test.zig+5-6| ... | ... | @@ -1451,11 +1451,11 @@ test "zig fmt: preserve spacing" { |
| 1451 | 1451 | \\const std = @import("std"); |
| 1452 | 1452 | \\ |
| 1453 | 1453 | \\pub fn main() !void { |
| 1454 | \\ var stdout_file = try std.io.getStdOut; | |
| 1455 | \\ var stdout_file = try std.io.getStdOut; | |
| 1454 | \\ var stdout_file = std.io.getStdOut; | |
| 1455 | \\ var stdout_file = std.io.getStdOut; | |
| 1456 | 1456 | \\ |
| 1457 | \\ var stdout_file = try std.io.getStdOut; | |
| 1458 | \\ var stdout_file = try std.io.getStdOut; | |
| 1457 | \\ var stdout_file = std.io.getStdOut; | |
| 1458 | \\ var stdout_file = std.io.getStdOut; | |
| 1459 | 1459 | \\} |
| 1460 | 1460 | \\ |
| 1461 | 1461 | ); |
| ... | ... | @@ -2565,8 +2565,7 @@ const maxInt = std.math.maxInt; |
| 2565 | 2565 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; |
| 2566 | 2566 | |
| 2567 | 2567 | fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *bool) ![]u8 { |
| 2568 | var stderr_file = try io.getStdErr(); | |
| 2569 | var stderr = &stderr_file.outStream().stream; | |
| 2568 | const stderr = &io.getStdErr().outStream().stream; | |
| 2570 | 2569 | |
| 2571 | 2570 | const tree = try std.zig.parse(allocator, source); |
| 2572 | 2571 | defer tree.deinit(); |
src-self-hosted/main.zig+4-7| ... | ... | @@ -56,13 +56,10 @@ pub fn main() !void { |
| 56 | 56 | // libc allocator is guaranteed to have this property. |
| 57 | 57 | const allocator = std.heap.c_allocator; |
| 58 | 58 | |
| 59 | var stdout_file = try std.io.getStdOut(); | |
| 60 | var stdout_out_stream = stdout_file.outStream(); | |
| 61 | stdout = &stdout_out_stream.stream; | |
| 59 | stdout = &std.io.getStdOut().outStream().stream; | |
| 62 | 60 | |
| 63 | stderr_file = try std.io.getStdErr(); | |
| 64 | var stderr_out_stream = stderr_file.outStream(); | |
| 65 | stderr = &stderr_out_stream.stream; | |
| 61 | stderr_file = std.io.getStdErr(); | |
| 62 | stderr = &stderr_file.outStream().stream; | |
| 66 | 63 | |
| 67 | 64 | const args = try process.argsAlloc(allocator); |
| 68 | 65 | // TODO I'm getting unreachable code here, which shouldn't happen |
| ... | ... | @@ -619,7 +616,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { |
| 619 | 616 | process.exit(1); |
| 620 | 617 | } |
| 621 | 618 | |
| 622 | var stdin_file = try io.getStdIn(); | |
| 619 | var stdin_file = io.getStdIn(); | |
| 623 | 620 | var stdin = stdin_file.inStream(); |
| 624 | 621 | |
| 625 | 622 | const source_code = try stdin.stream.readAllAlloc(allocator, max_src_size); |
src-self-hosted/stage1.zig+4-8| ... | ... | @@ -166,13 +166,9 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void { |
| 166 | 166 | try args_list.append(std.mem.toSliceConst(u8, argv[arg_i])); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | var stdout_file = try std.io.getStdOut(); | |
| 170 | var stdout_out_stream = stdout_file.outStream(); | |
| 171 | stdout = &stdout_out_stream.stream; | |
| 172 | ||
| 173 | stderr_file = try std.io.getStdErr(); | |
| 174 | var stderr_out_stream = stderr_file.outStream(); | |
| 175 | stderr = &stderr_out_stream.stream; | |
| 169 | stdout = &std.io.getStdOut().outStream().stream; | |
| 170 | stderr_file = std.io.getStdErr(); | |
| 171 | stderr = &stderr_file.outStream().stream; | |
| 176 | 172 | |
| 177 | 173 | const args = args_list.toSliceConst(); |
| 178 | 174 | var flags = try Args.parse(allocator, self_hosted_main.args_fmt_spec, args[2..]); |
| ... | ... | @@ -203,7 +199,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void { |
| 203 | 199 | process.exit(1); |
| 204 | 200 | } |
| 205 | 201 | |
| 206 | var stdin_file = try io.getStdIn(); | |
| 202 | const stdin_file = io.getStdIn(); | |
| 207 | 203 | var stdin = stdin_file.inStream(); |
| 208 | 204 | |
| 209 | 205 | const source_code = try stdin.stream.readAllAlloc(allocator, self_hosted_main.max_src_size); |
src-self-hosted/test.zig+2-2| ... | ... | @@ -181,7 +181,7 @@ pub const TestContext = struct { |
| 181 | 181 | }, |
| 182 | 182 | Compilation.Event.Error => |err| return err, |
| 183 | 183 | Compilation.Event.Fail => |msgs| { |
| 184 | var stderr = try std.io.getStdErr(); | |
| 184 | const stderr = std.io.getStdErr(); | |
| 185 | 185 | try stderr.write("build incorrectly failed:\n"); |
| 186 | 186 | for (msgs) |msg| { |
| 187 | 187 | defer msg.destroy(); |
| ... | ... | @@ -231,7 +231,7 @@ pub const TestContext = struct { |
| 231 | 231 | text, |
| 232 | 232 | ); |
| 233 | 233 | std.debug.warn("\n====found:========\n"); |
| 234 | var stderr = try std.io.getStdErr(); | |
| 234 | const stderr = std.io.getStdErr(); | |
| 235 | 235 | for (msgs) |msg| { |
| 236 | 236 | defer msg.destroy(); |
| 237 | 237 | try msg.printToFile(stderr, errmsg.Color.Auto); |
test/compare_output.zig+15-15| ... | ... | @@ -19,7 +19,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 19 | 19 | \\ |
| 20 | 20 | \\pub fn main() void { |
| 21 | 21 | \\ privateFunction(); |
| 22 | \\ const stdout = &(getStdOut() catch unreachable).outStream().stream; | |
| 22 | \\ const stdout = &getStdOut().outStream().stream; | |
| 23 | 23 | \\ stdout.print("OK 2\n") catch unreachable; |
| 24 | 24 | \\} |
| 25 | 25 | \\ |
| ... | ... | @@ -34,7 +34,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 34 | 34 | \\// purposefully conflicting function with main.zig |
| 35 | 35 | \\// but it's private so it should be OK |
| 36 | 36 | \\fn privateFunction() void { |
| 37 | \\ const stdout = &(getStdOut() catch unreachable).outStream().stream; | |
| 37 | \\ const stdout = &getStdOut().outStream().stream; | |
| 38 | 38 | \\ stdout.print("OK 1\n") catch unreachable; |
| 39 | 39 | \\} |
| 40 | 40 | \\ |
| ... | ... | @@ -60,7 +60,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 60 | 60 | tc.addSourceFile("foo.zig", |
| 61 | 61 | \\usingnamespace @import("std").io; |
| 62 | 62 | \\pub fn foo_function() void { |
| 63 | \\ const stdout = &(getStdOut() catch unreachable).outStream().stream; | |
| 63 | \\ const stdout = &getStdOut().outStream().stream; | |
| 64 | 64 | \\ stdout.print("OK\n") catch unreachable; |
| 65 | 65 | \\} |
| 66 | 66 | ); |
| ... | ... | @@ -71,7 +71,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 71 | 71 | \\ |
| 72 | 72 | \\pub fn bar_function() void { |
| 73 | 73 | \\ if (foo_function()) { |
| 74 | \\ const stdout = &(getStdOut() catch unreachable).outStream().stream; | |
| 74 | \\ const stdout = &getStdOut().outStream().stream; | |
| 75 | 75 | \\ stdout.print("OK\n") catch unreachable; |
| 76 | 76 | \\ } |
| 77 | 77 | \\} |
| ... | ... | @@ -103,7 +103,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 103 | 103 | \\pub const a_text = "OK\n"; |
| 104 | 104 | \\ |
| 105 | 105 | \\pub fn ok() void { |
| 106 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; | |
| 106 | \\ const stdout = &io.getStdOut().outStream().stream; | |
| 107 | 107 | \\ stdout.print(b_text) catch unreachable; |
| 108 | 108 | \\} |
| 109 | 109 | ); |
| ... | ... | @@ -121,7 +121,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 121 | 121 | \\const io = @import("std").io; |
| 122 | 122 | \\ |
| 123 | 123 | \\pub fn main() void { |
| 124 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; | |
| 124 | \\ const stdout = &io.getStdOut().outStream().stream; | |
| 125 | 125 | \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", @as(u32, 12), @as(u16, 0x12), @as(u8, 'a')) catch unreachable; |
| 126 | 126 | \\} |
| 127 | 127 | , "Hello, world!\n 12 12 a\n"); |
| ... | ... | @@ -264,7 +264,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 264 | 264 | \\ var x_local : i32 = print_ok(x); |
| 265 | 265 | \\} |
| 266 | 266 | \\fn print_ok(val: @typeOf(x)) @typeOf(foo) { |
| 267 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; | |
| 267 | \\ const stdout = &io.getStdOut().outStream().stream; | |
| 268 | 268 | \\ stdout.print("OK\n") catch unreachable; |
| 269 | 269 | \\ return 0; |
| 270 | 270 | \\} |
| ... | ... | @@ -346,7 +346,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 346 | 346 | \\pub fn main() void { |
| 347 | 347 | \\ const bar = Bar {.field2 = 13,}; |
| 348 | 348 | \\ const foo = Foo {.field1 = bar,}; |
| 349 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; | |
| 349 | \\ const stdout = &io.getStdOut().outStream().stream; | |
| 350 | 350 | \\ if (!foo.method()) { |
| 351 | 351 | \\ stdout.print("BAD\n") catch unreachable; |
| 352 | 352 | \\ } |
| ... | ... | @@ -360,7 +360,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 360 | 360 | cases.add("defer with only fallthrough", |
| 361 | 361 | \\const io = @import("std").io; |
| 362 | 362 | \\pub fn main() void { |
| 363 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; | |
| 363 | \\ const stdout = &io.getStdOut().outStream().stream; | |
| 364 | 364 | \\ stdout.print("before\n") catch unreachable; |
| 365 | 365 | \\ defer stdout.print("defer1\n") catch unreachable; |
| 366 | 366 | \\ defer stdout.print("defer2\n") catch unreachable; |
| ... | ... | @@ -373,7 +373,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 373 | 373 | \\const io = @import("std").io; |
| 374 | 374 | \\const os = @import("std").os; |
| 375 | 375 | \\pub fn main() void { |
| 376 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; | |
| 376 | \\ const stdout = &io.getStdOut().outStream().stream; | |
| 377 | 377 | \\ stdout.print("before\n") catch unreachable; |
| 378 | 378 | \\ defer stdout.print("defer1\n") catch unreachable; |
| 379 | 379 | \\ defer stdout.print("defer2\n") catch unreachable; |
| ... | ... | @@ -390,7 +390,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 390 | 390 | \\ do_test() catch return; |
| 391 | 391 | \\} |
| 392 | 392 | \\fn do_test() !void { |
| 393 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; | |
| 393 | \\ const stdout = &io.getStdOut().outStream().stream; | |
| 394 | 394 | \\ stdout.print("before\n") catch unreachable; |
| 395 | 395 | \\ defer stdout.print("defer1\n") catch unreachable; |
| 396 | 396 | \\ errdefer stdout.print("deferErr\n") catch unreachable; |
| ... | ... | @@ -409,7 +409,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 409 | 409 | \\ do_test() catch return; |
| 410 | 410 | \\} |
| 411 | 411 | \\fn do_test() !void { |
| 412 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; | |
| 412 | \\ const stdout = &io.getStdOut().outStream().stream; | |
| 413 | 413 | \\ stdout.print("before\n") catch unreachable; |
| 414 | 414 | \\ defer stdout.print("defer1\n") catch unreachable; |
| 415 | 415 | \\ errdefer stdout.print("deferErr\n") catch unreachable; |
| ... | ... | @@ -426,7 +426,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 426 | 426 | \\const io = @import("std").io; |
| 427 | 427 | \\ |
| 428 | 428 | \\pub fn main() void { |
| 429 | \\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream; | |
| 429 | \\ const stdout = &io.getStdOut().outStream().stream; | |
| 430 | 430 | \\ stdout.print(foo_txt) catch unreachable; |
| 431 | 431 | \\} |
| 432 | 432 | , "1234\nabcd\n"); |
| ... | ... | @@ -445,7 +445,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 445 | 445 | \\ |
| 446 | 446 | \\pub fn main() !void { |
| 447 | 447 | \\ var args_it = std.process.args(); |
| 448 | \\ var stdout_file = try io.getStdOut(); | |
| 448 | \\ var stdout_file = io.getStdOut(); | |
| 449 | 449 | \\ var stdout_adapter = stdout_file.outStream(); |
| 450 | 450 | \\ const stdout = &stdout_adapter.stream; |
| 451 | 451 | \\ var index: usize = 0; |
| ... | ... | @@ -486,7 +486,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 486 | 486 | \\ |
| 487 | 487 | \\pub fn main() !void { |
| 488 | 488 | \\ var args_it = std.process.args(); |
| 489 | \\ var stdout_file = try io.getStdOut(); | |
| 489 | \\ var stdout_file = io.getStdOut(); | |
| 490 | 490 | \\ var stdout_adapter = stdout_file.outStream(); |
| 491 | 491 | \\ const stdout = &stdout_adapter.stream; |
| 492 | 492 | \\ var index: usize = 0; |
test/standalone/brace_expansion/main.zig+2-2| ... | ... | @@ -179,8 +179,8 @@ fn expandNode(node: Node, output: *ArrayList(Buffer)) ExpandNodeError!void { |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | pub fn main() !void { |
| 182 | var stdin_file = try io.getStdIn(); | |
| 183 | var stdout_file = try io.getStdOut(); | |
| 182 | const stdin_file = io.getStdIn(); | |
| 183 | const stdout_file = io.getStdOut(); | |
| 184 | 184 | |
| 185 | 185 | var arena = std.heap.ArenaAllocator.init(std.heap.direct_allocator); |
| 186 | 186 | defer arena.deinit(); |
test/standalone/cat/main.zig+6-8| ... | ... | @@ -10,30 +10,28 @@ pub fn main() !void { |
| 10 | 10 | var args_it = process.args(); |
| 11 | 11 | const exe = try unwrapArg(args_it.next(allocator).?); |
| 12 | 12 | var catted_anything = false; |
| 13 | var stdout_file = try io.getStdOut(); | |
| 13 | const stdout_file = io.getStdOut(); | |
| 14 | 14 | |
| 15 | 15 | while (args_it.next(allocator)) |arg_or_err| { |
| 16 | 16 | const arg = try unwrapArg(arg_or_err); |
| 17 | 17 | if (mem.eql(u8, arg, "-")) { |
| 18 | 18 | catted_anything = true; |
| 19 | var stdin_file = try io.getStdIn(); | |
| 20 | try cat_file(&stdout_file, &stdin_file); | |
| 19 | try cat_file(stdout_file, io.getStdIn()); | |
| 21 | 20 | } else if (arg[0] == '-') { |
| 22 | 21 | return usage(exe); |
| 23 | 22 | } else { |
| 24 | var file = File.openRead(arg) catch |err| { | |
| 23 | const file = File.openRead(arg) catch |err| { | |
| 25 | 24 | warn("Unable to open file: {}\n", @errorName(err)); |
| 26 | 25 | return err; |
| 27 | 26 | }; |
| 28 | 27 | defer file.close(); |
| 29 | 28 | |
| 30 | 29 | catted_anything = true; |
| 31 | try cat_file(&stdout_file, &file); | |
| 30 | try cat_file(stdout_file, file); | |
| 32 | 31 | } |
| 33 | 32 | } |
| 34 | 33 | if (!catted_anything) { |
| 35 | var stdin_file = try io.getStdIn(); | |
| 36 | try cat_file(&stdout_file, &stdin_file); | |
| 34 | try cat_file(stdout_file, io.getStdIn()); | |
| 37 | 35 | } |
| 38 | 36 | } |
| 39 | 37 | |
| ... | ... | @@ -42,7 +40,7 @@ fn usage(exe: []const u8) !void { |
| 42 | 40 | return error.Invalid; |
| 43 | 41 | } |
| 44 | 42 | |
| 45 | fn cat_file(stdout: *File, file: *File) !void { | |
| 43 | fn cat_file(stdout: File, file: File) !void { | |
| 46 | 44 | var buf: [1024 * 4]u8 = undefined; |
| 47 | 45 | |
| 48 | 46 | while (true) { |
test/standalone/guess_number/main.zig+1-2| ... | ... | @@ -4,8 +4,7 @@ const io = std.io; |
| 4 | 4 | const fmt = std.fmt; |
| 5 | 5 | |
| 6 | 6 | pub fn main() !void { |
| 7 | var stdout_file = try io.getStdOut(); | |
| 8 | const stdout = &stdout_file.outStream().stream; | |
| 7 | const stdout = &io.getStdOut().outStream().stream; | |
| 9 | 8 | |
| 10 | 9 | try stdout.print("Welcome to the Guess Number Game in Zig.\n"); |
| 11 | 10 |
test/standalone/hello_world/hello.zig+1-1| ... | ... | @@ -2,7 +2,7 @@ const std = @import("std"); |
| 2 | 2 | |
| 3 | 3 | pub fn main() !void { |
| 4 | 4 | // If this program is run without stdout attached, exit with an error. |
| 5 | const stdout_file = try std.io.getStdOut(); | |
| 5 | const stdout_file = std.io.getStdOut(); | |
| 6 | 6 | // If this program encounters pipe failure when printing to stdout, exit |
| 7 | 7 | // with an error. |
| 8 | 8 | try stdout_file.write("Hello, world!\n"); |