diff options
| author | Alan CHUNG <[email protected]> | 2024-03-25 16:39:45 +0800 |
|---|---|---|
| committer | Alan CHUNG <[email protected]> | 2024-03-25 16:39:45 +0800 |
| commit | 74a6e60e17d8e71f9df37e3ac6ae30b4718e6034 (patch) | |
| tree | 01cff67b27f75542fe6d1c6a37f75a7ea9987a85 | |
| parent | 23b11a7509915b8c02b9329a78f2df22fe2eac5f (diff) | |
| download | ziglings-74a6e60e17d8e71f9df37e3ac6ae30b4718e6034.tar.xz ziglings-74a6e60e17d8e71f9df37e3ac6ae30b4718e6034.zip | |
add patch files for 106_files.zig
| -rw-r--r-- | exercises/106_files.zig | 8 | ||||
| -rw-r--r-- | patches/patches/106_files.patch | bin | 0 -> 2630 bytes |
2 files changed, 4 insertions, 4 deletions
diff --git a/exercises/106_files.zig b/exercises/106_files.zig index ffa0f86..0b593ed 100644 --- a/exercises/106_files.zig +++ b/exercises/106_files.zig @@ -35,8 +35,8 @@ pub fn main() !void { // by doing nothing // // we want to catch error.PathAlreadyExists and do nothing - ??? => { - ??? + error.PathAlreadyExists => { + return; }, // if is any other unexpected error we just propagate it through else => return e, @@ -46,7 +46,7 @@ pub fn main() !void { // wait a minute // opening a directory might fail! // what should we do here? - const output_dir: std.fs.Dir = cwd.openDir("output", .{}); + const output_dir: std.fs.Dir = try cwd.openDir("output", .{}); // we try to open the file `zigling.txt`, // and propagate the error up if there are any errors @@ -56,7 +56,7 @@ pub fn main() !void { // but here we are not yet done writing to the file // if only there are a keyword in zig that // allow you "defer" code execute to the end of scope... - file.close(); + defer file.close(); // !you are not allow to switch this two lines to before file closing line! const byte_written = try file.write("It's zigling time!"); diff --git a/patches/patches/106_files.patch b/patches/patches/106_files.patch Binary files differnew file mode 100644 index 0000000..07852c0 --- /dev/null +++ b/patches/patches/106_files.patch |
