mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
std.Io: delete CWriter
it shan't be missed
This commit is contained in:
parent
f34b4780b7
commit
d509bc933f
@ -448,9 +448,6 @@ pub const bufferedReaderSize = @import("Io/buffered_reader.zig").bufferedReaderS
|
||||
pub const FixedBufferStream = @import("Io/fixed_buffer_stream.zig").FixedBufferStream;
|
||||
pub const fixedBufferStream = @import("Io/fixed_buffer_stream.zig").fixedBufferStream;
|
||||
|
||||
pub const CWriter = @import("Io/c_writer.zig").CWriter;
|
||||
pub const cWriter = @import("Io/c_writer.zig").cWriter;
|
||||
|
||||
pub const LimitedReader = @import("Io/limited_reader.zig").LimitedReader;
|
||||
pub const limitedReader = @import("Io/limited_reader.zig").limitedReader;
|
||||
|
||||
@ -903,7 +900,6 @@ test {
|
||||
_ = @import("Io/buffered_atomic_file.zig");
|
||||
_ = @import("Io/buffered_reader.zig");
|
||||
_ = @import("Io/buffered_writer.zig");
|
||||
_ = @import("Io/c_writer.zig");
|
||||
_ = @import("Io/counting_writer.zig");
|
||||
_ = @import("Io/counting_reader.zig");
|
||||
_ = @import("Io/fixed_buffer_stream.zig");
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const io = std.io;
|
||||
const testing = std.testing;
|
||||
|
||||
pub const CWriter = io.GenericWriter(*std.c.FILE, std.fs.File.WriteError, cWriterWrite);
|
||||
|
||||
pub fn cWriter(c_file: *std.c.FILE) CWriter {
|
||||
return .{ .context = c_file };
|
||||
}
|
||||
|
||||
fn cWriterWrite(c_file: *std.c.FILE, bytes: []const u8) std.fs.File.WriteError!usize {
|
||||
const amt_written = std.c.fwrite(bytes.ptr, 1, bytes.len, c_file);
|
||||
if (amt_written >= 0) return amt_written;
|
||||
switch (@as(std.c.E, @enumFromInt(std.c._errno().*))) {
|
||||
.SUCCESS => unreachable,
|
||||
.INVAL => unreachable,
|
||||
.FAULT => unreachable,
|
||||
.AGAIN => unreachable, // this is a blocking API
|
||||
.BADF => unreachable, // always a race condition
|
||||
.DESTADDRREQ => unreachable, // connect was never called
|
||||
.DQUOT => return error.DiskQuota,
|
||||
.FBIG => return error.FileTooBig,
|
||||
.IO => return error.InputOutput,
|
||||
.NOSPC => return error.NoSpaceLeft,
|
||||
.PERM => return error.PermissionDenied,
|
||||
.PIPE => return error.BrokenPipe,
|
||||
else => |err| return std.posix.unexpectedErrno(err),
|
||||
}
|
||||
}
|
||||
|
||||
test cWriter {
|
||||
if (!builtin.link_libc or builtin.os.tag == .wasi) return error.SkipZigTest;
|
||||
|
||||
const filename = "tmp_io_test_file.txt";
|
||||
const out_file = std.c.fopen(filename, "w") orelse return error.UnableToOpenTestFile;
|
||||
defer {
|
||||
_ = std.c.fclose(out_file);
|
||||
std.fs.cwd().deleteFileZ(filename) catch {};
|
||||
}
|
||||
|
||||
const writer = cWriter(out_file);
|
||||
try writer.print("hi: {}\n", .{@as(i32, 123)});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user