authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-20 17:02:01-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-22 09:41:43-07:00
logd509bc933fe749cad270e11a7f3be88e1ec9a1a7
treecd8635a5b78b14eeca95750d467a8a4f883ea72b
parentf34b4780b7bd52d14df253d0762d9c73db8eb226

std.Io: delete CWriter

it shan't be missed

2 files changed, 0 insertions(+), 48 deletions(-)

lib/std/Io.zig-4
......@@ -448,9 +448,6 @@ pub const bufferedReaderSize = @import("Io/buffered_reader.zig").bufferedReaderS
448448pub const FixedBufferStream = @import("Io/fixed_buffer_stream.zig").FixedBufferStream;
449449pub const fixedBufferStream = @import("Io/fixed_buffer_stream.zig").fixedBufferStream;
450450
451pub const CWriter = @import("Io/c_writer.zig").CWriter;
452pub const cWriter = @import("Io/c_writer.zig").cWriter;
453
454451pub const LimitedReader = @import("Io/limited_reader.zig").LimitedReader;
455452pub const limitedReader = @import("Io/limited_reader.zig").limitedReader;
456453
......@@ -903,7 +900,6 @@ test {
903900 _ = @import("Io/buffered_atomic_file.zig");
904901 _ = @import("Io/buffered_reader.zig");
905902 _ = @import("Io/buffered_writer.zig");
906 _ = @import("Io/c_writer.zig");
907903 _ = @import("Io/counting_writer.zig");
908904 _ = @import("Io/counting_reader.zig");
909905 _ = @import("Io/fixed_buffer_stream.zig");
lib/std/Io/c_writer.zig deleted-44
......@@ -1,44 +0,0 @@
1const std = @import("../std.zig");
2const builtin = @import("builtin");
3const io = std.io;
4const testing = std.testing;
5
6pub const CWriter = io.GenericWriter(*std.c.FILE, std.fs.File.WriteError, cWriterWrite);
7
8pub fn cWriter(c_file: *std.c.FILE) CWriter {
9 return .{ .context = c_file };
10}
11
12fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!usize {
13 const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, c_file);
14 if (amt_written >= 0) return amt_written;
15 switch (@as(std.c.E, @enumFromInt(std.c._errno().*))) {
16 .SUCCESS => unreachable,
17 .INVAL => unreachable,
18 .FAULT => unreachable,
19 .AGAIN => unreachable, // this is a blocking API
20 .BADF => unreachable, // always a race condition
21 .DESTADDRREQ => unreachable, // connect was never called
22 .DQUOT => return error.DiskQuota,
23 .FBIG => return error.FileTooBig,
24 .IO => return error.InputOutput,
25 .NOSPC => return error.NoSpaceLeft,
26 .PERM => return error.PermissionDenied,
27 .PIPE => return error.BrokenPipe,
28 else => |err| return std.posix.unexpectedErrno(err),
29 }
30}
31
32test cWriter {
33 if (!builtin.link_libc or builtin.os.tag == .wasi) return error.SkipZigTest;
34
35 const filename = "tmp_io_test_file.txt";
36 const out_file = std.c.fopen(filename, "w") orelse return error.UnableToOpenTestFile;
37 defer {
38 _ = std.c.fclose(out_file);
39 std.fs.cwd().deleteFileZ(filename) catch {};
40 }
41
42 const writer = cWriter(out_file);
43 try writer.print("hi: {}\n", .{@as(i32, 123)});
44}