From 74a6e60e17d8e71f9df37e3ac6ae30b4718e6034 Mon Sep 17 00:00:00 2001 From: Alan CHUNG Date: Mon, 25 Mar 2024 16:39:45 +0800 Subject: [PATCH] add patch files for 106_files.zig --- exercises/106_files.zig | 8 ++++---- patches/patches/106_files.patch | Bin 0 -> 2630 bytes 2 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 patches/patches/106_files.patch 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 new file mode 100644 index 0000000000000000000000000000000000000000..07852c0ac3ba3a479f29f602a321c832be2497dd GIT binary patch literal 2630 zcmb_e+iu!G5S`~r{fC8@rXo108hTaRRB9jk);}QTVxXl48B?H9em(6uGad|%i4;<; z4C~#Q*_ktEX8reeAQMS2g0wM4c*`-5) z2s*t7>pYbw&`o8aX9e{m#tDhM!6^~OIjnZ%t-OT90B7)gdT@b3ZTj3k%3o@?bR6sX zrCj3VHhk;IDLf9aR?cmAE=xqf$Wr|N0e2|a$H5BejxsFL&=6ucnAL{GwiLHuP zZZl}4IdYgGn)e5AzCrfy!_sJ2si4e1tY&gYL~xATwH zVBLnb!OB=_{QGE{G~*pYf>P`@F&_3VdQa5IQX)$`jGcB9NU={fDoFVGV?{3jjj>`j zRrVU%thRu4=3xkq(x;M{ee9-1Hi&i(@A%s-e0m36=4yb-Nid7#i~35;Sz{~R@tADy zM4IY_+iC*$0L^Q;LBBBel}vq{2YG?k@t%YOn37j+-8za#$#vq%yx8p#2q}mvnKO@r7^9BRh~+sGkvSrHETozCq%d VdS+jDUZ2#QpvMl;Q=40S{{f*XhbsU8 literal 0 HcmV?d00001