From 77623e0a5bdbfb271bc02f26cf2b377ec16b55ec Mon Sep 17 00:00:00 2001 From: Christian Segundo Date: Thu, 1 Dec 2022 20:07:30 +0100 Subject: quick refactor to add utils --- day-1/main.zig | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'day-1/main.zig') diff --git a/day-1/main.zig b/day-1/main.zig index b2760fb..fa89e3f 100644 --- a/day-1/main.zig +++ b/day-1/main.zig @@ -1,18 +1,11 @@ const std = @import("std"); +const slurp = @import("util/file.zig").slurp; var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); pub fn main() !void { - var path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; - const path = try std.fs.realpath("./input", &path_buffer); - - const file = try std.fs.openFileAbsolute(path, .{}); - defer file.close(); - - const file_size = (try file.stat()).size; - - const file_buffer = try file.readToEndAlloc(allocator, file_size); + const file_buffer = try slurp(allocator, "./input"); defer allocator.free(file_buffer); var iter = std.mem.split(u8, file_buffer, "\n"); -- cgit v1.2.3