authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-09-27 15:06:44+10:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-09-27 15:06:44+10:00
log4786eaedda76a3fc43510be67f9c04915b5fd703
tree784ab8a92824cea345bb5b5573b53799208558fd
parentcffab89730eb6f4183e2628d8b0d007df809436a
signaturelock-open Commit is signed but in an unrecognized format.

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


1 files changed, 5 insertions(+), 16 deletions(-)

test/standalone/cat/main.zig+5-16
...@@ -50,23 +50,12 @@ fn usage(exe: []const u8) !void {...@@ -50,23 +50,12 @@ fn usage(exe: []const u8) !void {
5050
51// TODO use copy_file_range51// TODO use copy_file_range
52fn cat_file(stdout: fs.File, file: fs.File) !void {52fn cat_file(stdout: fs.File, file: fs.File) !void {
53 var buf: [1024 * 4]u8 = undefined;53 var fifo = std.fifo.LinearFifo(u8, .{ .Static = 1024 * 4 }).init();
5454
55 while (true) {55 fifo.pump(file.reader(), stdout.writer()) catch |err| {
56 const bytes_read = file.read(buf[0..]) catch |err| {56 warn("Unable to read from stream or write to stdout: {}\n", .{@errorName(err)});
57 warn("Unable to read from stream: {}\n", .{@errorName(err)});57 return err;
58 return err;58 };
59 };
60
61 if (bytes_read == 0) {
62 break;
63 }
64
65 stdout.writeAll(buf[0..bytes_read]) catch |err| {
66 warn("Unable to write to stdout: {}\n", .{@errorName(err)});
67 return err;
68 };
69 }
70}59}
7160
72fn unwrapArg(arg: anyerror![]u8) ![]u8 {61fn unwrapArg(arg: anyerror![]u8) ![]u8 {