| 1 |
const std = @import("std"); |
| 2 |
const io = std.io; |
| 3 |
const os = std.os; |
| 4 |
const allocator = std.heap.page_allocator; |
| 5 |
const stdout = std.io.getStdOut(); |
| 6 |
const warn = std.log.warn; |
| 7 |
|
| 8 |
pub fn main() !void { |
| 9 |
// Allocate arguments from the the operating system. |
| 10 |
const args = try std.process.argsAlloc(allocator); |
| 11 |
defer std.process.argsFree(allocator, args); |
| 12 |
|
| 13 |
// loop on the args, skipping the filename (args[0]) |
| 14 |
for (args[1..args.len]) |arg| { |
| 15 |
|
| 16 |
// open the file from a relative path, as "/" is pre-opened and the CWD. |
| 17 |
const file = std.fs.cwd().openFile(arg, .{ .mode = .read_only }) catch |err| { |
| 18 |
warn("Unable to open file {s}: {s}\n", .{ arg, @errorName(err) }); |
| 19 |
return err; |
| 20 |
}; |
| 21 |
defer file.close(); |
| 22 |
|
| 23 |
// Write the contents to stdout |
| 24 |
stdout.writeFileAll(file, .{}) catch |err| { |
| 25 |
warn("Unable to write contents to stdout: {s}\n", .{@errorName(err)}); |
| 26 |
return err; |
| 27 |
}; |
| 28 |
} |
| 29 |
} |