From 17cbee012c16ec2f36ddba5d467183c8d94165f8 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Sat, 1 Jan 2022 21:32:30 +1100 Subject: update to zig 0.9.0 --- strip-store-paths/strip-store-paths.zig | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/strip-store-paths/strip-store-paths.zig b/strip-store-paths/strip-store-paths.zig index 58d7504..243bd4a 100644 --- a/strip-store-paths/strip-store-paths.zig +++ b/strip-store-paths/strip-store-paths.zig @@ -3,21 +3,12 @@ const std = @import("std"); pub const File = struct { ptr: []align(std.mem.page_size) u8, len: u64, - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, - pub fn init(fd: std.os.fd_t, allocator: *std.mem.Allocator) !File { + pub fn init(fd: std.os.fd_t, allocator: std.mem.Allocator) !File { var stats = try std.os.fstat(fd); - var ptr = try std.os.mmap(null, - @intCast(usize, stats.size), - std.os.PROT_READ | std.os.PROT_WRITE, - std.os.MAP_SHARED, - fd, - 0); - return File { - .ptr = ptr, - .len = @intCast(u64, stats.size), - .allocator = allocator - }; + var ptr = try std.os.mmap(null, @intCast(usize, stats.size), std.os.PROT.READ | std.os.PROT.WRITE, std.os.MAP.SHARED, fd, 0); + return File{ .ptr = ptr, .len = @intCast(u64, stats.size), .allocator = allocator }; } pub fn deinit(self: *File) void { @@ -30,7 +21,7 @@ pub const File = struct { pub fn main() !void { var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); - const allocator = &arena.allocator; + const allocator = arena.allocator(); const args = try std.process.argsAlloc(allocator); if (args.len != 2) { @@ -40,7 +31,7 @@ pub fn main() !void { const path = args[1]; // mmap input - var fd = try std.os.open(path, std.os.O_RDWR, 0); + var fd = try std.os.open(path, std.os.O.RDWR, 0); var input = try File.init(fd, allocator); defer input.deinit(); @@ -48,7 +39,7 @@ pub fn main() !void { var i: usize = 0; const needle = "/nix/store/"; while (std.mem.indexOfPos(u8, input.ptr, i, needle)) |idx| { - i = idx + needle.len; + i = idx + needle.len; var j = i + 32; // pos of - in a true path if (j < input.len and input.ptr[j] == '-') { std.mem.copy(u8, input.ptr[i..], "00000000000000000000000000000000"); -- cgit v1.2.3