Files
ziglings/patches/patches/109_files.patch
T
2026-06-29 17:14:05 +00:00

30 lines
1.1 KiB
Diff

--- exercises/109_files.zig 2026-06-29 17:08:04.124224900 +0000
+++ answers/109_files.zig 2026-06-29 17:13:20.696220533 +0000
@@ -41,7 +41,7 @@
// by doing nothing
//
// we want to catch error.PathAlreadyExists and do nothing
- ??? => {},
+ error.PathAlreadyExists => {},
// if there's any other unexpected error we just propagate it through
else => return e,
};
@@ -50,7 +50,7 @@
// wait a minute...
// opening a directory might fail!
// what should we do here?
- var output_dir: std.Io.Dir = cwd.openDir(io, "output", .{});
+ var output_dir: std.Io.Dir = try cwd.openDir(io, "output", .{});
defer output_dir.close(io);
// we try to open the file `zigling.txt`,
@@ -61,7 +61,7 @@
// but here we are not yet done writing to the file
// if only there were a keyword in Zig that
// allowed you to "defer" code execution to the end of the scope...
- file.close(io);
+ defer file.close(io);
// you are not allowed to move these lines above the file closing line!
var file_writer = file.writer(io, &.{});