| ... | @@ -50,23 +50,12 @@ fn usage(exe: []const u8) !void { | ... | @@ -50,23 +50,12 @@ fn usage(exe: []const u8) !void { |
| 50 | | 50 | |
| 51 | // TODO use copy_file_range | 51 | // TODO use copy_file_range |
| 52 | fn cat_file(stdout: fs.File, file: fs.File) !void { | 52 | fn 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(); |
| 54 | | 54 | |
| 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 | } |
| 71 | | 60 | |
| 72 | fn unwrapArg(arg: anyerror![]u8) ![]u8 { | 61 | fn unwrapArg(arg: anyerror![]u8) ![]u8 { |