zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 4786eaedda76a3fc43510be67f9c04915b5fd703 (tree)
parent cffab89730eb6f4183e2628d8b0d007df809436a
Author: daurnimator <quae@daurnimator.com>
Date:   Sun, 27 Sep 2020 15:06:44 +1000

test/standalone/cat: use fifo.pump()

Diffstat:
Mtest/standalone/cat/main.zig | 21+++++----------------
1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/test/standalone/cat/main.zig b/test/standalone/cat/main.zig @@ -50,23 +50,12 @@ fn usage(exe: []const u8) !void { // TODO use copy_file_range fn cat_file(stdout: fs.File, file: fs.File) !void { - var buf: [1024 * 4]u8 = undefined; + var fifo = std.fifo.LinearFifo(u8, .{ .Static = 1024 * 4 }).init(); - while (true) { - const bytes_read = file.read(buf[0..]) catch |err| { - warn("Unable to read from stream: {}\n", .{@errorName(err)}); - return err; - }; - - if (bytes_read == 0) { - break; - } - - stdout.writeAll(buf[0..bytes_read]) catch |err| { - warn("Unable to write to stdout: {}\n", .{@errorName(err)}); - return err; - }; - } + fifo.pump(file.reader(), stdout.writer()) catch |err| { + warn("Unable to read from stream or write to stdout: {}\n", .{@errorName(err)}); + return err; + }; } fn unwrapArg(arg: anyerror![]u8) ![]u8 {