authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-04-04 19:26:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 16:35:26-07:00
log890a02c3456dce7242aa65e5093b31f9d8a417bc
tree2720536bb22c61b9405344cdcb85abcc862ffb07
parent6c48aad991f64f7e5bb92af498cc4cbddca9895e

std.io: move getStdIn, getStdOut, getStdErr functions to fs.File

preparing to rearrange std.io namespace into an interface

36 files changed, 183 insertions(+), 203 deletions(-)

lib/compiler/test_runner.zig+3-3
......@@ -69,8 +69,8 @@ fn mainServer() !void {
6969 @disableInstrumentation();
7070 var server = try std.zig.Server.init(.{
7171 .gpa = fba.allocator(),
72 .in = std.io.getStdIn(),
73 .out = std.io.getStdOut(),
72 .in = .stdin(),
73 .out = .stdout(),
7474 .zig_version = builtin.zig_version_string,
7575 });
7676 defer server.deinit();
......@@ -191,7 +191,7 @@ fn mainTerminal() void {
191191 .root_name = "Test",
192192 .estimated_total_items = test_fn_list.len,
193193 });
194 const have_tty = std.io.getStdErr().isTty();
194 const have_tty = std.fs.File.stderr().isTty();
195195
196196 var async_frame_buffer: []align(builtin.target.stackAlignment()) u8 = undefined;
197197 // TODO this is on the next line (using `undefined` above) because otherwise zig incorrectly
lib/std/Build.zig+3-3
......@@ -2677,7 +2677,7 @@ pub const LazyPath = union(enum) {
26772677 .root_dir = Cache.Directory.cwd(),
26782678 .sub_path = gen.file.path orelse {
26792679 std.debug.lockStdErr();
2680 const stderr = std.io.getStdErr();
2680 const stderr: fs.File = .stderr();
26812681 dumpBadGetPathHelp(gen.file.step, stderr, src_builder, asking_step) catch {};
26822682 std.debug.unlockStdErr();
26832683 @panic("misconfigured build script");
......@@ -2766,11 +2766,11 @@ fn dumpBadDirnameHelp(
27662766 comptime msg: []const u8,
27672767 args: anytype,
27682768) anyerror!void {
2769 var buffered_writer = debug.lockStdErr2();
2769 var buffered_writer = debug.lockStdErr2(&.{});
27702770 defer debug.unlockStdErr();
27712771 const w = &buffered_writer;
27722772
2773 const stderr = io.getStdErr();
2773 const stderr: fs.File = .stderr();
27742774 try w.print(msg, args);
27752775
27762776 const tty_config = std.io.tty.detectConfig(stderr);
lib/std/Build/Fuzz.zig+2-2
......@@ -124,7 +124,7 @@ fn rebuildTestsWorkerRunFallible(run: *Step.Run, ttyconf: std.io.tty.Config, par
124124 const show_stderr = compile.step.result_stderr.len > 0;
125125
126126 if (show_error_msgs or show_compile_errors or show_stderr) {
127 var bw = std.debug.lockStdErr2();
127 var bw = std.debug.lockStdErr2(&.{});
128128 defer std.debug.unlockStdErr();
129129 build_runner.printErrorMessages(gpa, &compile.step, .{ .ttyconf = ttyconf }, &bw, false) catch {};
130130 }
......@@ -151,7 +151,7 @@ fn fuzzWorkerRun(
151151
152152 run.rerunInFuzzMode(web_server, unit_test_index, prog_node) catch |err| switch (err) {
153153 error.MakeFailed => {
154 var bw = std.debug.lockStdErr2();
154 var bw = std.debug.lockStdErr2(&.{});
155155 defer std.debug.unlockStdErr();
156156 build_runner.printErrorMessages(gpa, &run.step, .{ .ttyconf = ttyconf }, &bw, false) catch {};
157157 return;
lib/std/Build/Step/Compile.zig+2-2
......@@ -1018,7 +1018,7 @@ fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking
10181018
10191019 const generated_file = maybe_path orelse {
10201020 std.debug.lockStdErr();
1021 const stderr = std.io.getStdErr();
1021 const stderr: fs.File = .stderr();
10221022
10231023 std.Build.dumpBadGetPathHelp(&compile.step, stderr, compile.step.owner, asking_step) catch {};
10241024
......@@ -1027,7 +1027,7 @@ fn getGeneratedFilePath(compile: *Compile, comptime tag_name: []const u8, asking
10271027
10281028 const path = generated_file.path orelse {
10291029 std.debug.lockStdErr();
1030 const stderr = std.io.getStdErr();
1030 const stderr: fs.File = .stderr();
10311031
10321032 std.Build.dumpBadGetPathHelp(&compile.step, stderr, compile.step.owner, asking_step) catch {};
10331033
lib/std/Progress.zig+1-1
......@@ -451,7 +451,7 @@ pub fn start(options: Options) Node {
451451 if (options.disable_printing) {
452452 return Node.none;
453453 }
454 const stderr = std.io.getStdErr();
454 const stderr: std.fs.File = .stderr();
455455 global_progress.terminal = stderr;
456456 if (stderr.getOrEnableAnsiEscapeSupport()) {
457457 global_progress.terminal_mode = .ansi_escape_codes;
lib/std/Random/benchmark.zig+1-1
......@@ -122,7 +122,7 @@ fn mode(comptime x: comptime_int) comptime_int {
122122}
123123
124124pub fn main() !void {
125 const stdout = std.io.getStdOut().writer();
125 const stdout = std.fs.File.stdout().writer();
126126
127127 var buffer: [1024]u8 = undefined;
128128 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
lib/std/builtin.zig+1-1
......@@ -51,7 +51,7 @@ pub const StackTrace = struct {
5151 const debug_info = std.debug.getSelfDebugInfo() catch |err| {
5252 return writer.print("\nUnable to print stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});
5353 };
54 const tty_config = std.io.tty.detectConfig(std.io.getStdErr());
54 const tty_config = std.io.tty.detectConfig(.stderr());
5555 try writer.writeAll("\n");
5656 std.debug.writeStackTrace(self, writer, debug_info, tty_config) catch |err| {
5757 try writer.print("Unable to print stack trace: {s}\n", .{@errorName(err)});
lib/std/crypto/benchmark.zig+1-1
......@@ -458,7 +458,7 @@ fn mode(comptime x: comptime_int) comptime_int {
458458}
459459
460460pub fn main() !void {
461 const stdout = std.io.getStdOut().writer();
461 const stdout = std.fs.File.stdout().writer();
462462
463463 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
464464 defer arena.deinit();
lib/std/debug.zig+23-23
......@@ -210,15 +210,15 @@ pub fn unlockStdErr() void {
210210///
211211/// Returns a `std.io.BufferedWriter` with empty buffer, meaning that it is
212212/// in fact unbuffered and does not need to be flushed.
213pub fn lockStdErr2() std.io.BufferedWriter {
213pub fn lockStdErr2(buffer: []u8) std.io.BufferedWriter {
214214 std.Progress.lockStdErr();
215 return io.getStdErr().writer().unbuffered();
215 return std.fs.File.stderr().writer().buffered(buffer);
216216}
217217
218218/// Print to stderr, unbuffered, and silently returning on failure. Intended
219219/// for use in "printf debugging." Use `std.log` functions for proper logging.
220220pub fn print(comptime fmt: []const u8, args: anytype) void {
221 var bw = lockStdErr2();
221 var bw = lockStdErr2(&.{});
222222 defer unlockStdErr();
223223 nosuspend bw.print(fmt, args) catch return;
224224}
......@@ -242,9 +242,9 @@ pub fn getSelfDebugInfo() !*SelfInfo {
242242/// Tries to print a hexadecimal view of the bytes, unbuffered, and ignores any error returned.
243243/// Obtains the stderr mutex while dumping.
244244pub fn dumpHex(bytes: []const u8) void {
245 var bw = lockStdErr2();
245 var bw = lockStdErr2(&.{});
246246 defer unlockStdErr();
247 const ttyconf = std.io.tty.detectConfig(std.io.getStdErr());
247 const ttyconf = std.io.tty.detectConfig(.stderr());
248248 dumpHexFallible(&bw, ttyconf, bytes) catch {};
249249}
250250
......@@ -320,7 +320,7 @@ test dumpHexFallible {
320320
321321/// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.
322322pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
323 var stderr = lockStdErr2();
323 var stderr = lockStdErr2(&.{});
324324 defer unlockStdErr();
325325 nosuspend dumpCurrentStackTraceToWriter(start_addr, &stderr) catch return;
326326}
......@@ -341,7 +341,7 @@ pub fn dumpCurrentStackTraceToWriter(start_addr: ?usize, writer: *std.io.Buffere
341341 try writer.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});
342342 return;
343343 };
344 writeCurrentStackTrace(writer, debug_info, io.tty.detectConfig(io.getStdErr()), start_addr) catch |err| {
344 writeCurrentStackTrace(writer, debug_info, io.tty.detectConfig(.stderr()), start_addr) catch |err| {
345345 try writer.print("Unable to dump stack trace: {s}\n", .{@errorName(err)});
346346 return;
347347 };
......@@ -426,7 +426,7 @@ pub fn dumpStackTraceFromBase(context: *ThreadContext, stderr: *std.io.BufferedW
426426 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;
427427 return;
428428 };
429 const tty_config = io.tty.detectConfig(io.getStdErr());
429 const tty_config = io.tty.detectConfig(.stderr());
430430 if (native_os == .windows) {
431431 // On x86_64 and aarch64, the stack will be unwound using RtlVirtualUnwind using the context
432432 // provided by the exception handler. On x86, RtlVirtualUnwind doesn't exist. Instead, a new backtrace
......@@ -516,13 +516,13 @@ pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
516516 nosuspend {
517517 if (builtin.target.cpu.arch.isWasm()) {
518518 if (native_os == .wasi) {
519 var stderr = lockStdErr2();
519 var stderr = lockStdErr2(&.{});
520520 defer unlockStdErr();
521521 stderr.writeAll("Unable to dump stack trace: not implemented for Wasm\n") catch return;
522522 }
523523 return;
524524 }
525 var stderr = lockStdErr2();
525 var stderr = lockStdErr2(&.{});
526526 defer unlockStdErr();
527527 if (builtin.strip_debug_info) {
528528 stderr.writeAll("Unable to dump stack trace: debug info stripped\n") catch return;
......@@ -532,7 +532,7 @@ pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
532532 stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return;
533533 return;
534534 };
535 writeStackTrace(stack_trace, &stderr, debug_info, io.tty.detectConfig(io.getStdErr())) catch |err| {
535 writeStackTrace(stack_trace, &stderr, debug_info, io.tty.detectConfig(.stderr())) catch |err| {
536536 stderr.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch return;
537537 return;
538538 };
......@@ -683,7 +683,7 @@ pub fn defaultPanic(
683683 _ = panicking.fetchAdd(1, .seq_cst);
684684
685685 {
686 var stderr = lockStdErr2();
686 var stderr = lockStdErr2(&.{});
687687 defer unlockStdErr();
688688
689689 if (builtin.single_threaded) {
......@@ -706,7 +706,7 @@ pub fn defaultPanic(
706706 // A panic happened while trying to print a previous panic message.
707707 // We're still holding the mutex but that's fine as we're going to
708708 // call abort().
709 io.getStdErr().writeAll("aborting due to recursive panic\n") catch {};
709 fs.File.stderr().writeAll("aborting due to recursive panic\n") catch {};
710710 },
711711 else => {}, // Panicked while printing the recursive panic message.
712712 };
......@@ -1468,7 +1468,8 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa
14681468}
14691469
14701470fn dumpSegfaultInfoPosix(sig: i32, code: i32, addr: usize, ctx_ptr: ?*anyopaque) void {
1471 var stderr = io.getStdErr().writer().unbuffered();
1471 var stderr = lockStdErr2(&.{});
1472 defer unlockStdErr();
14721473 _ = switch (sig) {
14731474 posix.SIG.SEGV => if (native_arch == .x86_64 and native_os == .linux and code == 128) // SI_KERNEL
14741475 // x86_64 doesn't have a full 64-bit virtual address space.
......@@ -1546,25 +1547,24 @@ fn handleSegfaultWindowsExtra(info: *windows.EXCEPTION_POINTERS, msg: u8, label:
15461547 _ = panicking.fetchAdd(1, .seq_cst);
15471548
15481549 {
1549 lockStdErr();
1550 var stderr = lockStdErr2(&.{});
15501551 defer unlockStdErr();
15511552
1552 dumpSegfaultInfoWindows(info, msg, label);
1553 dumpSegfaultInfoWindows(info, msg, label, &stderr);
15531554 }
15541555
15551556 waitForOtherThreadToFinishPanicking();
15561557 },
15571558 1 => {
15581559 panic_stage = 2;
1559 io.getStdErr().writeAll("aborting due to recursive panic\n") catch {};
1560 fs.File.stderr().writeAll("aborting due to recursive panic\n") catch {};
15601561 },
15611562 else => {},
15621563 };
15631564 posix.abort();
15641565}
15651566
1566fn dumpSegfaultInfoWindows(info: *windows.EXCEPTION_POINTERS, msg: u8, label: ?[]const u8) void {
1567 var stderr = io.getStdErr().writer().unbuffered();
1567fn dumpSegfaultInfoWindows(info: *windows.EXCEPTION_POINTERS, msg: u8, label: ?[]const u8, stderr: *std.io.BufferedWriter) void {
15681568 _ = switch (msg) {
15691569 0 => stderr.print("{s}\n", .{label.?}),
15701570 1 => stderr.print("Segmentation fault at address 0x{x}\n", .{info.ExceptionRecord.ExceptionInformation[1]}),
......@@ -1572,7 +1572,7 @@ fn dumpSegfaultInfoWindows(info: *windows.EXCEPTION_POINTERS, msg: u8, label: ?[
15721572 else => unreachable,
15731573 } catch posix.abort();
15741574
1575 dumpStackTraceFromBase(info.ContextRecord, &stderr);
1575 dumpStackTraceFromBase(info.ContextRecord, stderr);
15761576}
15771577
15781578pub fn dumpStackPointerAddr(prefix: []const u8) void {
......@@ -1598,7 +1598,7 @@ test "manage resources correctly" {
15981598 const writer = std.io.null_writer;
15991599 var di = try SelfInfo.open(testing.allocator);
16001600 defer di.deinit();
1601 try printSourceAtAddress(&di, writer, showMyTrace(), io.tty.detectConfig(std.io.getStdErr()));
1601 try printSourceAtAddress(&di, writer, showMyTrace(), io.tty.detectConfig(.stderr()));
16021602}
16031603
16041604noinline fn showMyTrace() usize {
......@@ -1664,8 +1664,8 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize
16641664 pub fn dump(t: @This()) void {
16651665 if (!enabled) return;
16661666
1667 const tty_config = io.tty.detectConfig(std.io.getStdErr());
1668 var stderr = lockStdErr2();
1667 const tty_config = io.tty.detectConfig(.stderr());
1668 var stderr = lockStdErr2(&.{});
16691669 defer unlockStdErr();
16701670 const end = @min(t.index, size);
16711671 const debug_info = getSelfDebugInfo() catch |err| {
lib/std/debug/simple_panic.zig+1-1
......@@ -15,7 +15,7 @@ pub fn call(msg: []const u8, ra: ?usize) noreturn {
1515 @branchHint(.cold);
1616 _ = ra;
1717 std.debug.lockStdErr();
18 const stderr = std.io.getStdErr();
18 const stderr: std.fs.File = .stderr();
1919 stderr.writeAll(msg) catch {};
2020 @trap();
2121}
lib/std/fs/File.zig+12
......@@ -168,6 +168,18 @@ pub const CreateFlags = struct {
168168 mode: Mode = default_mode,
169169};
170170
171pub fn stdout() File {
172 return .{ .handle = if (is_windows) windows.peb().ProcessParameters.hStdOutput else posix.STDOUT_FILENO };
173}
174
175pub fn stderr() File {
176 return .{ .handle = if (is_windows) windows.peb().ProcessParameters.hStdError else posix.STDERR_FILENO };
177}
178
179pub fn stdin() File {
180 return .{ .handle = if (is_windows) windows.peb().ProcessParameters.hStdInput else posix.STDIN_FILENO };
181}
182
171183/// Upon success, the stream is in an uninitialized state. To continue using it,
172184/// you must use the open() function.
173185pub fn close(self: File) void {
lib/std/hash/benchmark.zig+1-1
......@@ -346,7 +346,7 @@ fn mode(comptime x: comptime_int) comptime_int {
346346}
347347
348348pub fn main() !void {
349 const stdout = std.io.getStdOut().writer();
349 const stdout = std.fs.File.stdout().writer().unbuffered();
350350
351351 var buffer: [1024]u8 = undefined;
352352 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
lib/std/io.zig-48
......@@ -14,54 +14,6 @@ const File = std.fs.File;
1414const Allocator = std.mem.Allocator;
1515const Alignment = std.mem.Alignment;
1616
17fn getStdOutHandle() posix.fd_t {
18 if (is_windows) {
19 return windows.peb().ProcessParameters.hStdOutput;
20 }
21
22 if (@hasDecl(root, "os") and @hasDecl(root.os, "io") and @hasDecl(root.os.io, "getStdOutHandle")) {
23 return root.os.io.getStdOutHandle();
24 }
25
26 return posix.STDOUT_FILENO;
27}
28
29pub fn getStdOut() File {
30 return .{ .handle = getStdOutHandle() };
31}
32
33fn getStdErrHandle() posix.fd_t {
34 if (is_windows) {
35 return windows.peb().ProcessParameters.hStdError;
36 }
37
38 if (@hasDecl(root, "os") and @hasDecl(root.os, "io") and @hasDecl(root.os.io, "getStdErrHandle")) {
39 return root.os.io.getStdErrHandle();
40 }
41
42 return posix.STDERR_FILENO;
43}
44
45pub fn getStdErr() File {
46 return .{ .handle = getStdErrHandle() };
47}
48
49fn getStdInHandle() posix.fd_t {
50 if (is_windows) {
51 return windows.peb().ProcessParameters.hStdInput;
52 }
53
54 if (@hasDecl(root, "os") and @hasDecl(root.os, "io") and @hasDecl(root.os.io, "getStdInHandle")) {
55 return root.os.io.getStdInHandle();
56 }
57
58 return posix.STDIN_FILENO;
59}
60
61pub fn getStdIn() File {
62 return .{ .handle = getStdInHandle() };
63}
64
6517pub const Reader = @import("io/Reader.zig");
6618pub const Writer = @import("io/Writer.zig");
6719
lib/std/io/BufferedReader.zig+2-2
......@@ -421,9 +421,9 @@ pub fn takeByte(br: *BufferedReader) anyerror!u8 {
421421 return buffer[seek];
422422}
423423
424/// Same as `readByte` except the returned byte is signed.
424/// Same as `takeByte` except the returned byte is signed.
425425pub fn takeByteSigned(br: *BufferedReader) anyerror!i8 {
426 return @bitCast(try br.readByte());
426 return @bitCast(try br.takeByte());
427427}
428428
429429/// Asserts the buffer was initialized with a capacity at least `@sizeOf(T)`.
lib/std/io/Reader.zig+23-7
......@@ -2,7 +2,7 @@ const std = @import("../std.zig");
22const Reader = @This();
33const assert = std.debug.assert;
44
5context: *anyopaque,
5context: ?*anyopaque,
66vtable: *const VTable,
77
88pub const VTable = struct {
......@@ -19,8 +19,8 @@ pub const VTable = struct {
1919 ///
2020 /// If this is `null` it is equivalent to always returning
2121 /// `error.Unseekable`.
22 posRead: ?*const fn (ctx: *anyopaque, bw: *std.io.BufferedWriter, limit: Limit, offset: u64) anyerror!Status,
23 posReadVec: ?*const fn (ctx: *anyopaque, data: []const []u8, offset: u64) anyerror!Status,
22 posRead: ?*const fn (ctx: ?*anyopaque, bw: *std.io.BufferedWriter, limit: Limit, offset: u64) Result,
23 posReadVec: ?*const fn (ctx: ?*anyopaque, data: []const []u8, offset: u64) VecResult,
2424
2525 /// Writes bytes from the internally tracked stream position to `bw`, or
2626 /// returns `error.Unstreamable`, indicating `posRead` should be used
......@@ -37,14 +37,30 @@ pub const VTable = struct {
3737 ///
3838 /// If this is `null` it is equivalent to always returning
3939 /// `error.Unstreamable`.
40 streamRead: ?*const fn (ctx: *anyopaque, bw: *std.io.BufferedWriter, limit: Limit) anyerror!Status,
41 streamReadVec: ?*const fn (ctx: *anyopaque, data: []const []u8) anyerror!Status,
40 streamRead: ?*const fn (ctx: ?*anyopaque, bw: *std.io.BufferedWriter, limit: Limit) Result,
41 streamReadVec: ?*const fn (ctx: ?*anyopaque, data: []const []u8) VecResult,
4242};
4343
4444pub const Len = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(usize) - 1 } });
4545
46pub const Status = packed struct(usize) {
47 /// Number of bytes that were written to `writer`.
46pub const VecResult = struct {
47 /// Even when a failure occurs, `Effect.written` may be nonzero, and
48 /// `Effect.end` may be true.
49 failure: anyerror!void,
50 effect: VecEffect,
51};
52
53pub const Result = struct {
54 /// Even when a failure occurs, `Effect.written` may be nonzero, and
55 /// `Effect.end` may be true.
56 failure: anyerror!void,
57 write_effect: Effect,
58 read_effect: Effect,
59};
60
61pub const Effect = packed struct(usize) {
62 /// Number of bytes that were read from the reader or written to the
63 /// writer.
4864 len: Len,
4965 /// Indicates end of stream.
5066 end: bool,
lib/std/io/Writer.zig+18-2
......@@ -17,7 +17,7 @@ pub const VTable = struct {
1717 /// Number of bytes returned may be zero, which does not mean
1818 /// end-of-stream. A subsequent call may return nonzero, or may signal end
1919 /// of stream via an error.
20 writeSplat: *const fn (ctx: *anyopaque, data: []const []const u8, splat: usize) anyerror!usize,
20 writeSplat: *const fn (ctx: *anyopaque, data: []const []const u8, splat: usize) Result,
2121
2222 /// Writes contents from an open file. `headers` are written first, then `len`
2323 /// bytes of `file` starting from `offset`, then `trailers`.
......@@ -38,7 +38,23 @@ pub const VTable = struct {
3838 /// zero, they can be forwarded directly to `VTable.writev`.
3939 headers_and_trailers: []const []const u8,
4040 headers_len: usize,
41 ) anyerror!usize,
41 ) Result,
42};
43
44pub const Len = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(usize) - 1 } });
45
46pub const Result = struct {
47 /// Even when a failure occurs, `Effect.written` may be nonzero, and
48 /// `Effect.end` may be true.
49 failure: anyerror!void,
50 effect: Effect,
51};
52
53pub const Effect = packed struct(usize) {
54 /// Number of bytes that were written to `writer`.
55 len: Len,
56 /// Indicates end of stream.
57 end: bool,
4258};
4359
4460pub const Offset = enum(u64) {
lib/std/json/dynamic.zig+1-1
......@@ -51,7 +51,7 @@ pub const Value = union(enum) {
5151 }
5252
5353 pub fn dump(v: Value) void {
54 var bw = std.debug.lockStdErr2();
54 var bw = std.debug.lockStdErr2(&.{});
5555 defer std.debug.unlockStdErr();
5656
5757 json.Stringify.value(v, .{}, &bw) catch return;
lib/std/log.zig+2-6
......@@ -47,7 +47,7 @@
4747//! // Print the message to stderr, silently ignoring any errors
4848//! std.debug.lockStdErr();
4949//! defer std.debug.unlockStdErr();
50//! const stderr = std.io.getStdErr().writer();
50//! const stderr = std.fs.File.stderr().writer();
5151//! nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return;
5252//! }
5353//!
......@@ -149,11 +149,7 @@ pub fn defaultLog(
149149 const level_txt = comptime message_level.asText();
150150 const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
151151 var buffer: [1024]u8 = undefined;
152 var bw: std.io.BufferedWriter = .{
153 .unbuffered_writer = std.io.getStdErr().writer(),
154 .buffer = &buffer,
155 };
156 std.debug.lockStdErr();
152 var bw: std.io.BufferedWriter = std.debug.lockStdErr2(&buffer);
157153 defer std.debug.unlockStdErr();
158154 nosuspend {
159155 bw.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;
lib/std/testing.zig+2-2
......@@ -390,9 +390,9 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const
390390 const actual_window = actual[window_start..@min(actual.len, window_start + max_window_size)];
391391 const actual_truncated = window_start + actual_window.len < actual.len;
392392
393 var bw = std.debug.lockStdErr2();
393 var bw = std.debug.lockStdErr2(&.{});
394394 defer std.debug.unlockStdErr();
395 const ttyconf = std.io.tty.detectConfig(std.io.getStdErr());
395 const ttyconf = std.io.tty.detectConfig(.stderr());
396396 var differ = if (T == u8) BytesDiffer{
397397 .expected = expected_window,
398398 .actual = actual_window,
lib/std/unicode/throughput_test.zig+1-1
......@@ -39,7 +39,7 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {
3939}
4040
4141pub fn main() !void {
42 const stdout = std.io.getStdOut().writer();
42 const stdout = std.fs.File.stdout().writer();
4343
4444 try stdout.print("short ASCII strings\n", .{});
4545 {
lib/std/zig.zig+1-1
......@@ -48,7 +48,7 @@ pub const Color = enum {
4848
4949 pub fn get_tty_conf(color: Color) std.io.tty.Config {
5050 return switch (color) {
51 .auto => std.io.tty.detectConfig(std.io.getStdErr()),
51 .auto => std.io.tty.detectConfig(.stderr()),
5252 .on => .escape_codes,
5353 .off => .no_color,
5454 };
lib/std/zig/ErrorBundle.zig+2-6
......@@ -157,13 +157,9 @@ pub const RenderOptions = struct {
157157};
158158
159159pub fn renderToStdErr(eb: ErrorBundle, options: RenderOptions) void {
160 std.debug.lockStdErr();
161 defer std.debug.unlockStdErr();
162160 var buffer: [256]u8 = undefined;
163 var bw: std.io.BufferedWriter = .{
164 .unbuffered_writer = std.io.getStdErr().writer(),
165 .buffer = &buffer,
166 };
161 var bw = std.debug.lockStdErr2(&buffer);
162 defer std.debug.unlockStdErr();
167163 renderToWriter(eb, options, &bw) catch return;
168164 bw.flush() catch return;
169165}
lib/std/zig/llvm/Builder.zig+3-2
......@@ -9493,7 +9493,8 @@ pub fn asmValue(
94939493}
94949494
94959495pub fn dump(self: *Builder) void {
9496 self.print(std.io.getStdErr().writer()) catch {};
9496 const stderr: std.fs.File = .stderr();
9497 self.print(stderr.writer().unbuffered()) catch {};
94979498}
94989499
94999500pub fn printToFile(self: *Builder, path: []const u8) Allocator.Error!bool {
......@@ -9509,7 +9510,7 @@ pub fn printToFile(self: *Builder, path: []const u8) Allocator.Error!bool {
95099510 return true;
95109511}
95119512
9512pub fn print(self: *Builder, writer: anytype) (@TypeOf(writer).Error || Allocator.Error)!void {
9513pub fn print(self: *Builder, writer: *std.io.BufferedWriter) (@TypeOf(writer).Error || Allocator.Error)!void {
95139514 var bw = std.io.bufferedWriter(writer);
95149515 try self.printUnbuffered(bw.writer());
95159516 try bw.flush();
lib/std/zig/parser_test.zig+8-7
......@@ -6463,24 +6463,25 @@ const maxInt = std.math.maxInt;
64636463var fixed_buffer_mem: [100 * 1024]u8 = undefined;
64646464
64656465fn testParse(source: [:0]const u8, allocator: mem.Allocator, anything_changed: *bool) ![]u8 {
6466 const stderr = io.getStdErr().writer();
6466 const stderr: std.fs.File = .stderr();
6467 const stderr_writer = stderr.writer().unbuffered();
64676468
64686469 var tree = try std.zig.Ast.parse(allocator, source, .zig);
64696470 defer tree.deinit(allocator);
64706471
64716472 for (tree.errors) |parse_error| {
64726473 const loc = tree.tokenLocation(0, parse_error.token);
6473 try stderr.print("(memory buffer):{d}:{d}: error: ", .{ loc.line + 1, loc.column + 1 });
6474 try tree.renderError(parse_error, stderr);
6475 try stderr.print("\n{s}\n", .{source[loc.line_start..loc.line_end]});
6474 try stderr_writer.print("(memory buffer):{d}:{d}: error: ", .{ loc.line + 1, loc.column + 1 });
6475 try tree.renderError(parse_error, stderr_writer);
6476 try stderr_writer.print("\n{s}\n", .{source[loc.line_start..loc.line_end]});
64766477 {
64776478 var i: usize = 0;
64786479 while (i < loc.column) : (i += 1) {
6479 try stderr.writeAll(" ");
6480 try stderr_writer.writeAll(" ");
64806481 }
6481 try stderr.writeAll("^");
6482 try stderr_writer.writeAll("^");
64826483 }
6483 try stderr.writeAll("\n");
6484 try stderr_writer.writeAll("\n");
64846485 }
64856486 if (tree.errors.len != 0) {
64866487 return error.ParseError;
lib/std/zig/perf_test.zig+1-1
......@@ -22,7 +22,7 @@ pub fn main() !void {
2222 const bytes_per_sec_float = @as(f64, @floatFromInt(source.len * iterations)) / elapsed_s;
2323 const bytes_per_sec = @as(u64, @intFromFloat(@floor(bytes_per_sec_float)));
2424
25 var stdout_file = std.io.getStdOut();
25 var stdout_file: std.fs.File = .stdout();
2626 const stdout = stdout_file.writer();
2727 try stdout.print("parsing speed: {:.2}/s, {:.2} used \n", .{
2828 fmtIntSizeBin(bytes_per_sec),
src/Air/print.zig+2-2
......@@ -72,13 +72,13 @@ pub fn writeInst(
7272}
7373
7474pub fn dump(air: Air, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {
75 var bw = std.debug.lockStdErr2();
75 var bw = std.debug.lockStdErr2(&.{});
7676 defer std.debug.unlockStdErr();
7777 air.write(&bw, pt, liveness);
7878}
7979
8080pub fn dumpInst(air: Air, inst: Air.Inst.Index, pt: Zcu.PerThread, liveness: ?Air.Liveness) void {
81 var bw = std.debug.lockStdErr2();
81 var bw = std.debug.lockStdErr2(&.{});
8282 defer std.debug.unlockStdErr();
8383 air.writeInst(&bw, inst, pt, liveness);
8484}
src/Compilation.zig+9-7
......@@ -1880,7 +1880,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18801880
18811881 if (options.verbose_llvm_cpu_features) {
18821882 if (options.root_mod.resolved_target.llvm_cpu_features) |cf| print: {
1883 var stderr = std.debug.lockStdErr2();
1883 var stderr = std.debug.lockStdErr2(&.{});
18841884 defer std.debug.unlockStdErr();
18851885 nosuspend {
18861886 stderr.print("compilation: {s}\n", .{options.root_name}) catch break :print;
......@@ -3942,7 +3942,8 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
39423942 // This AU is referenced and has a transitive compile error, meaning it referenced something with a compile error.
39433943 // However, we haven't reported any such error.
39443944 // This is a compiler bug.
3945 const stderr = std.io.getStdErr().writer();
3945 var stderr = std.debug.lockStdErr2(&.{});
3946 defer std.debug.unlockStdErr();
39463947 try stderr.writeAll("referenced transitive analysis errors, but none actually emitted\n");
39473948 try stderr.print("{} [transitive failure]\n", .{zcu.fmtAnalUnit(failed_unit)});
39483949 while (ref) |r| {
......@@ -7222,13 +7223,14 @@ pub fn lockAndSetMiscFailure(
72227223}
72237224
72247225pub fn dump_argv(argv: []const []const u8) void {
7225 std.debug.lockStdErr();
7226 var stderr = std.debug.lockStdErr2(&.{});
72267227 defer std.debug.unlockStdErr();
7227 const stderr = std.io.getStdErr().writer();
7228 for (argv[0 .. argv.len - 1]) |arg| {
7229 nosuspend stderr.print("{s} ", .{arg}) catch return;
7228 nosuspend {
7229 for (argv[0 .. argv.len - 1]) |arg| {
7230 stderr.print("{s} ", .{arg}) catch return;
7231 }
7232 stderr.print("{s}\n", .{argv[argv.len - 1]}) catch {};
72307233 }
7231 nosuspend stderr.print("{s}\n", .{argv[argv.len - 1]}) catch {};
72327234}
72337235
72347236pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend {
src/InternPool.zig+17-15
......@@ -11267,8 +11267,9 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
1126711267}
1126811268
1126911269fn dumpAllFallible(ip: *const InternPool) anyerror!void {
11270 var bw = std.io.bufferedWriter(std.io.getStdErr().writer());
11271 const w = bw.writer();
11270 var buffer: [4096]u8 = undefined;
11271 var bw = std.debug.lockStdErr2(&buffer);
11272 defer std.debug.unlockStdErr();
1127211273 for (ip.locals, 0..) |*local, tid| {
1127311274 const items = local.shared.items.view();
1127411275 for (
......@@ -11277,12 +11278,12 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {
1127711278 0..,
1127811279 ) |tag, data, index| {
1127911280 const i = Index.Unwrapped.wrap(.{ .tid = @enumFromInt(tid), .index = @intCast(index) }, ip);
11280 try w.print("${d} = {s}(", .{ i, @tagName(tag) });
11281 try bw.print("${d} = {s}(", .{ i, @tagName(tag) });
1128111282 switch (tag) {
1128211283 .removed => {},
1128311284
11284 .simple_type => try w.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(@intFromEnum(i))))}),
11285 .simple_value => try w.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(@intFromEnum(i))))}),
11285 .simple_type => try bw.print("{s}", .{@tagName(@as(SimpleType, @enumFromInt(@intFromEnum(i))))}),
11286 .simple_value => try bw.print("{s}", .{@tagName(@as(SimpleValue, @enumFromInt(@intFromEnum(i))))}),
1128611287
1128711288 .type_int_signed,
1128811289 .type_int_unsigned,
......@@ -11355,14 +11356,14 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {
1135511356 .func_coerced,
1135611357 .union_value,
1135711358 .memoized_call,
11358 => try w.print("{d}", .{data}),
11359 => try bw.print("{d}", .{data}),
1135911360
1136011361 .opt_null,
1136111362 .type_slice,
1136211363 .only_possible_value,
11363 => try w.print("${d}", .{data}),
11364 => try bw.print("${d}", .{data}),
1136411365 }
11365 try w.writeAll(")\n");
11366 try bw.writeAll(")\n");
1136611367 }
1136711368 }
1136811369 try bw.flush();
......@@ -11377,9 +11378,6 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
1137711378 defer arena_allocator.deinit();
1137811379 const arena = arena_allocator.allocator();
1137911380
11380 var bw = std.io.bufferedWriter(std.io.getStdErr().writer());
11381 const w = bw.writer();
11382
1138311381 var instances: std.AutoArrayHashMapUnmanaged(Index, std.ArrayListUnmanaged(Index)) = .empty;
1138411382 for (ip.locals, 0..) |*local, tid| {
1138511383 const items = local.shared.items.view().slice();
......@@ -11402,6 +11400,10 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
1140211400 }
1140311401 }
1140411402
11403 var buffer: [4096]u8 = undefined;
11404 var bw = std.debug.lockStdErr2(&buffer);
11405 defer std.debug.unlockStdErr();
11406
1140511407 const SortContext = struct {
1140611408 values: []std.ArrayListUnmanaged(Index),
1140711409 pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool {
......@@ -11413,19 +11415,19 @@ pub fn dumpGenericInstancesFallible(ip: *const InternPool, allocator: Allocator)
1141311415 var it = instances.iterator();
1141411416 while (it.next()) |entry| {
1141511417 const generic_fn_owner_nav = ip.getNav(ip.funcDeclInfo(entry.key_ptr.*).owner_nav);
11416 try w.print("{} ({}): \n", .{ generic_fn_owner_nav.name.fmt(ip), entry.value_ptr.items.len });
11418 try bw.print("{} ({}): \n", .{ generic_fn_owner_nav.name.fmt(ip), entry.value_ptr.items.len });
1141711419 for (entry.value_ptr.items) |index| {
1141811420 const unwrapped_index = index.unwrap(ip);
1141911421 const func = ip.extraFuncInstance(unwrapped_index.tid, unwrapped_index.getExtra(ip), unwrapped_index.getData(ip));
1142011422 const owner_nav = ip.getNav(func.owner_nav);
11421 try w.print(" {}: (", .{owner_nav.name.fmt(ip)});
11423 try bw.print(" {}: (", .{owner_nav.name.fmt(ip)});
1142211424 for (func.comptime_args.get(ip)) |arg| {
1142311425 if (arg != .none) {
1142411426 const key = ip.indexToKey(arg);
11425 try w.print(" {} ", .{key});
11427 try bw.print(" {} ", .{key});
1142611428 }
1142711429 }
11428 try w.writeAll(")\n");
11430 try bw.writeAll(")\n");
1142911431 }
1143011432 }
1143111433
src/Package/Fetch.zig+1-4
......@@ -1643,10 +1643,7 @@ fn computeHash(f: *Fetch, pkg_path: Cache.Path, filter: Filter) RunError!Compute
16431643
16441644fn dumpHashInfo(all_files: []const *const HashedFile) !void {
16451645 var buffer: [4096]u8 = undefined;
1646 var bw: std.io.BufferedWriter = .{
1647 .unbuffered_writer = std.io.getStdOut().writer(),
1648 .buffer = &buffer,
1649 };
1646 var bw: std.io.BufferedWriter = std.fs.File.stdout().writer().buffered(&buffer);
16501647 for (all_files) |hashed_file| {
16511648 try bw.print("{s}: {x}: {s}\n", .{
16521649 @tagName(hashed_file.kind), &hashed_file.hash, hashed_file.normalized_path,
src/crash_report.zig+7-8
......@@ -80,7 +80,7 @@ fn dumpStatusReport() !void {
8080 var fba = std.heap.FixedBufferAllocator.init(&crash_heap);
8181 const allocator = fba.allocator();
8282
83 const stderr = io.getStdErr().writer();
83 const stderr = std.fs.File.stderr.writer().unbuffered();
8484 const block: *Sema.Block = anal.block;
8585 const zcu = anal.sema.pt.zcu;
8686
......@@ -271,8 +271,7 @@ const StackContext = union(enum) {
271271 debug.dumpStackTraceFromBase(context);
272272 },
273273 .not_supported => {
274 const stderr = io.getStdErr().writer();
275 stderr.writeAll("Stack trace not supported on this platform.\n") catch {};
274 std.fs.File.stderr().writeAll("Stack trace not supported on this platform.\n") catch {};
276275 },
277276 }
278277 }
......@@ -379,7 +378,7 @@ const PanicSwitch = struct {
379378
380379 state.recover_stage = .release_mutex;
381380
382 const stderr = io.getStdErr().writer();
381 const stderr = std.fs.File.stderr().writer().unbuffered();
383382 if (builtin.single_threaded) {
384383 stderr.print("panic: ", .{}) catch goTo(releaseMutex, .{state});
385384 } else {
......@@ -406,7 +405,7 @@ const PanicSwitch = struct {
406405 recover(state, trace, stack, msg);
407406
408407 state.recover_stage = .release_mutex;
409 const stderr = io.getStdErr().writer();
408 const stderr = std.fs.File.stderr().writer().unbuffered();
410409 stderr.writeAll("\nOriginal Error:\n") catch {};
411410 goTo(reportStack, .{state});
412411 }
......@@ -477,7 +476,7 @@ const PanicSwitch = struct {
477476 recover(state, trace, stack, msg);
478477
479478 state.recover_stage = .silent_abort;
480 const stderr = io.getStdErr().writer();
479 var stderr = std.fs.File.stderr().writer().unbuffered();
481480 stderr.writeAll("Aborting...\n") catch {};
482481 goTo(abort, .{});
483482 }
......@@ -505,7 +504,7 @@ const PanicSwitch = struct {
505504 // lower the verbosity, and restore it at the end if we don't panic.
506505 state.recover_verbosity = .message_only;
507506
508 const stderr = io.getStdErr().writer();
507 var stderr = std.fs.File.stderr().writer().unbuffered();
509508 stderr.writeAll("\nPanicked during a panic: ") catch {};
510509 stderr.writeAll(msg) catch {};
511510 stderr.writeAll("\nInner panic stack:\n") catch {};
......@@ -519,7 +518,7 @@ const PanicSwitch = struct {
519518 .message_only => {
520519 state.recover_verbosity = .silent;
521520
522 const stderr = io.getStdErr().writer();
521 var stderr = std.fs.File.stderr().writer().unbuffered();
523522 stderr.writeAll("\nPanicked while dumping inner panic stack: ") catch {};
524523 stderr.writeAll(msg) catch {};
525524 stderr.writeAll("\n") catch {};
src/fmt.zig+4-8
......@@ -49,7 +49,7 @@ pub fn run(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
4949 const arg = args[i];
5050 if (mem.startsWith(u8, arg, "-")) {
5151 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
52 try std.io.getStdOut().writeAll(usage_fmt);
52 try std.fs.File.stdout().writeAll(usage_fmt);
5353 return process.cleanExit();
5454 } else if (mem.eql(u8, arg, "--color")) {
5555 if (i + 1 >= args.len) {
......@@ -89,8 +89,7 @@ pub fn run(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
8989 fatal("cannot use --stdin with positional arguments", .{});
9090 }
9191
92 const stdin = std.io.getStdIn();
93 const source_code = std.zig.readSourceFileToEndAlloc(gpa, stdin, null) catch |err| {
92 const source_code = std.zig.readSourceFileToEndAlloc(gpa, .stdin(), null) catch |err| {
9493 fatal("unable to read stdin: {}", .{err});
9594 };
9695 defer gpa.free(source_code);
......@@ -145,7 +144,7 @@ pub fn run(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
145144 process.exit(code);
146145 }
147146
148 return std.io.getStdOut().writeAll(formatted);
147 return std.fs.File.stdout().writeAll(formatted);
149148 }
150149
151150 if (input_files.items.len == 0) {
......@@ -153,10 +152,7 @@ pub fn run(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
153152 }
154153
155154 var stdout_buffer: [4096]u8 = undefined;
156 var stdout: std.io.BufferedWriter = .{
157 .buffer = &stdout_buffer,
158 .unbuffered_writer = std.io.getStdOut().writer(),
159 };
155 var stdout: std.io.BufferedWriter = std.fs.File.stdout().writer().buffered(&stdout_buffer);
160156
161157 var fmt: Fmt = .{
162158 .gpa = gpa,
src/libs/mingw.zig+2-2
......@@ -304,7 +304,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
304304 const include_dir = try comp.dirs.zig_lib.join(arena, &.{ "libc", "mingw", "def-include" });
305305
306306 if (comp.verbose_cc) print: {
307 var stderr = std.debug.lockStdErr2();
307 var stderr = std.debug.lockStdErr2(&.{});
308308 defer std.debug.unlockStdErr();
309309 nosuspend stderr.print("def file: {s}\n", .{def_file_path}) catch break :print;
310310 nosuspend stderr.print("include dir: {s}\n", .{include_dir}) catch break :print;
......@@ -325,7 +325,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
325325
326326 for (aro_comp.diagnostics.list.items) |diagnostic| {
327327 if (diagnostic.kind == .@"fatal error" or diagnostic.kind == .@"error") {
328 aro.Diagnostics.render(&aro_comp, std.io.tty.detectConfig(std.io.getStdErr()));
328 aro.Diagnostics.render(&aro_comp, std.io.tty.detectConfig(.stderr()));
329329 return error.AroPreprocessorFailed;
330330 }
331331 }
src/link/Elf/gc.zig+2-2
......@@ -163,13 +163,13 @@ fn prune(elf_file: *Elf) void {
163163}
164164
165165pub fn dumpPrunedAtoms(elf_file: *Elf) !void {
166 const stderr = std.io.getStdErr().writer();
166 var stderr = std.debug.lockStdErr2(&.{});
167 defer std.debug.unlockStdErr();
167168 for (elf_file.objects.items) |index| {
168169 const file = elf_file.file(index).?;
169170 for (file.atoms()) |atom_index| {
170171 const atom = file.atom(atom_index) orelse continue;
171172 if (!atom.alive)
172 // TODO should we simply print to stderr?
173173 try stderr.print("link: removing unused section '{s}' in file '{}'\n", .{
174174 atom.name(elf_file),
175175 atom.file(elf_file).?.fmtPath(),
src/main.zig+22-22
......@@ -344,7 +344,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
344344 return @import("print_targets.zig").cmdTargets(arena, cmd_args);
345345 } else if (mem.eql(u8, cmd, "version")) {
346346 dev.check(.version_command);
347 try std.io.getStdOut().writeAll(build_options.version ++ "\n");
347 try fs.File.stdout().writeAll(build_options.version ++ "\n");
348348 // Check libc++ linkage to make sure Zig was built correctly, but only
349349 // for "env" and "version" to avoid affecting the startup time for
350350 // build-critical commands (check takes about ~10 μs)
......@@ -360,10 +360,10 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
360360 });
361361 } else if (mem.eql(u8, cmd, "zen")) {
362362 dev.check(.zen_command);
363 return io.getStdOut().writeAll(info_zen);
363 return fs.File.stdout().writeAll(info_zen);
364364 } else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) {
365365 dev.check(.help_command);
366 return io.getStdOut().writeAll(usage);
366 return fs.File.stdout().writeAll(usage);
367367 } else if (mem.eql(u8, cmd, "ast-check")) {
368368 return cmdAstCheck(arena, cmd_args);
369369 } else if (mem.eql(u8, cmd, "detect-cpu")) {
......@@ -1040,7 +1040,7 @@ fn buildOutputType(
10401040 };
10411041 } else if (mem.startsWith(u8, arg, "-")) {
10421042 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
1043 try io.getStdOut().writeAll(usage_build_generic);
1043 try fs.File.stdout().writeAll(usage_build_generic);
10441044 return cleanExit();
10451045 } else if (mem.eql(u8, arg, "--")) {
10461046 if (arg_mode == .run) {
......@@ -2768,9 +2768,9 @@ fn buildOutputType(
27682768 } else if (mem.eql(u8, arg, "-V")) {
27692769 warn("ignoring request for supported emulations: unimplemented", .{});
27702770 } else if (mem.eql(u8, arg, "-v")) {
2771 try std.io.getStdOut().writeAll("zig ld " ++ build_options.version ++ "\n");
2771 try fs.File.stdout().writeAll("zig ld " ++ build_options.version ++ "\n");
27722772 } else if (mem.eql(u8, arg, "--version")) {
2773 try std.io.getStdOut().writeAll("zig ld " ++ build_options.version ++ "\n");
2773 try fs.File.stdout().writeAll("zig ld " ++ build_options.version ++ "\n");
27742774 process.exit(0);
27752775 } else {
27762776 fatal("unsupported linker arg: {s}", .{arg});
......@@ -3330,7 +3330,7 @@ fn buildOutputType(
33303330 var hasher = Cache.Hasher.init("0123456789abcdef");
33313331 var w = io.multiWriter(.{ f.writer(), hasher.writer() });
33323332 var fifo = std.fifo.LinearFifo(u8, .{ .Static = 4096 }).init();
3333 try fifo.pump(io.getStdIn().reader(), w.writer());
3333 try fifo.pump(fs.File.stdin().reader().unbuffered(), w.writer().unbuffered());
33343334
33353335 var bin_digest: Cache.BinDigest = undefined;
33363336 hasher.final(&bin_digest);
......@@ -3548,15 +3548,15 @@ fn buildOutputType(
35483548 if (show_builtin) {
35493549 const builtin_opts = comp.root_mod.getBuiltinOptions(comp.config);
35503550 const source = try builtin_opts.generate(arena);
3551 return std.io.getStdOut().writeAll(source);
3551 return fs.File.stdout().writeAll(source);
35523552 }
35533553 switch (listen) {
35543554 .none => {},
35553555 .stdio => {
35563556 try serve(
35573557 comp,
3558 std.io.getStdIn(),
3559 std.io.getStdOut(),
3558 fs.File.stdin(),
3559 fs.File.stdout(),
35603560 test_exec_args.items,
35613561 self_exe_path,
35623562 arg_mode,
......@@ -4618,7 +4618,7 @@ fn cmdTranslateC(
46184618 fatal("unable to open cached translated zig file '{s}{s}{s}': {s}", .{ path, fs.path.sep_str, out_zig_path, @errorName(err) });
46194619 };
46204620 defer zig_file.close();
4621 try io.getStdOut().writeFileAll(zig_file, .{});
4621 try fs.File.stdout().writeFileAll(zig_file, .{});
46224622 return cleanExit();
46234623 }
46244624}
......@@ -4648,7 +4648,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
46484648 if (mem.eql(u8, arg, "-s") or mem.eql(u8, arg, "--strip")) {
46494649 strip = true;
46504650 } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
4651 try io.getStdOut().writeAll(usage_init);
4651 try fs.File.stdout().writeAll(usage_init);
46524652 return cleanExit();
46534653 } else {
46544654 fatal("unrecognized parameter: '{s}'", .{arg});
......@@ -5478,7 +5478,7 @@ fn jitCmd(
54785478
54795479 if (options.server) {
54805480 var server = std.zig.Server{
5481 .out = std.io.getStdOut(),
5481 .out = fs.File.stdout(),
54825482 .in = undefined, // won't be receiving messages
54835483 .receive_fifo = undefined, // won't be receiving messages
54845484 };
......@@ -6011,7 +6011,7 @@ fn cmdAstCheck(
60116011 const arg = args[i];
60126012 if (mem.startsWith(u8, arg, "-")) {
60136013 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6014 try io.getStdOut().writeAll(usage_ast_check);
6014 try fs.File.stdout().writeAll(usage_ast_check);
60156015 return cleanExit();
60166016 } else if (mem.eql(u8, arg, "-t")) {
60176017 want_output_text = true;
......@@ -6062,7 +6062,7 @@ fn cmdAstCheck(
60626062 const tree = try Ast.parse(arena, source, mode);
60636063
60646064 var bw: std.io.BufferedWriter = .{
6065 .unbuffered_writer = io.getStdOut().writer(),
6065 .unbuffered_writer = fs.File.stdout().writer(),
60666066 .buffer = &stdout_buffer,
60676067 };
60686068
......@@ -6187,7 +6187,7 @@ fn cmdDetectCpu(args: []const []const u8) !void {
61876187 const arg = args[i];
61886188 if (mem.startsWith(u8, arg, "-")) {
61896189 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6190 const stdout = io.getStdOut().writer();
6190 const stdout = fs.File.stdout().writer();
61916191 try stdout.writeAll(detect_cpu_usage);
61926192 return cleanExit();
61936193 } else if (mem.eql(u8, arg, "--llvm")) {
......@@ -6281,7 +6281,7 @@ fn detectNativeCpuWithLLVM(
62816281
62826282fn printCpu(cpu: std.Target.Cpu) !void {
62836283 var bw: std.io.BufferedWriter = .{
6284 .unbuffered_writer = io.getStdOut().writer(),
6284 .unbuffered_writer = fs.File.stdout().writer(),
62856285 .buffer = &stdout_buffer,
62866286 };
62876287
......@@ -6331,7 +6331,7 @@ fn cmdDumpLlvmInts(
63316331 const dl = tm.createTargetDataLayout();
63326332 const context = llvm.Context.create();
63336333
6334 var bw = io.bufferedWriter(io.getStdOut().writer());
6334 var bw = io.bufferedWriter(fs.File.stdout().writer());
63356335 const stdout = bw.writer();
63366336
63376337 for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| {
......@@ -6364,7 +6364,7 @@ fn cmdDumpZir(
63646364 const zir = try Zcu.loadZirCache(arena, f);
63656365
63666366 var bw: std.io.BufferedWriter = .{
6367 .unbuffered_writer = io.getStdOut().writer(),
6367 .unbuffered_writer = fs.File.stdout().writer(),
63686368 .buffer = &stdout_buffer,
63696369 };
63706370
......@@ -6452,7 +6452,7 @@ fn cmdChangelist(
64526452 try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map);
64536453
64546454 var bw: std.io.BufferedWriter = .{
6455 .unbuffered_writer = io.getStdOut().writer(),
6455 .unbuffered_writer = fs.File.stdout().writer(),
64566456 .buffer = &stdout_buffer,
64576457 };
64586458 {
......@@ -6800,7 +6800,7 @@ fn cmdFetch(
68006800 const arg = args[i];
68016801 if (mem.startsWith(u8, arg, "-")) {
68026802 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
6803 const stdout = io.getStdOut().writer();
6803 const stdout = fs.File.stdout().writer();
68046804 try stdout.writeAll(usage_fetch);
68056805 return cleanExit();
68066806 } else if (mem.eql(u8, arg, "--global-cache-dir")) {
......@@ -6914,7 +6914,7 @@ fn cmdFetch(
69146914
69156915 const name = switch (save) {
69166916 .no => {
6917 try io.getStdOut().writer().print("{s}\n", .{package_hash_slice});
6917 try fs.File.stdout().writer().print("{s}\n", .{package_hash_slice});
69186918 return cleanExit();
69196919 },
69206920 .yes, .exact => |name| name: {
src/print_env.zig+1-4
......@@ -22,10 +22,7 @@ pub fn cmdEnv(arena: Allocator, args: []const []const u8) !void {
2222 const triple = try host.zigTriple(arena);
2323
2424 var buffer: [1024]u8 = undefined;
25 var bw: std.io.BufferedWriter = .{
26 .buffer = &buffer,
27 .unbuffered_writer = std.io.getStdOut().writer(),
28 };
25 var bw: std.io.BufferedWriter = std.fs.File.stdout().writer().buffered(&buffer);
2926 var jws: std.json.Stringify = .{ .writer = &bw, .options = .{ .whitespace = .indent_1 } };
3027
3128 try jws.beginObject();
src/print_targets.zig+1-4
......@@ -15,10 +15,7 @@ pub fn cmdTargets(arena: Allocator, args: []const []const u8) anyerror!void {
1515 _ = args;
1616 const host = std.zig.resolveTargetQueryOrFatal(.{});
1717 var buffer: [1024]u8 = undefined;
18 var bw: std.io.BufferedWriter = .{
19 .unbuffered_writer = io.getStdOut().writer(),
20 .buffer = &buffer,
21 };
18 var bw = fs.File.stdout().writer().buffered(&buffer);
2219 try print(arena, &bw, host);
2320 try bw.flush();
2421}