From b0d74c0cadc81dd344e427b5fa0e12bacf9054e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Fri, 25 Feb 2022 13:59:35 +0200 Subject: [PATCH] formatting --- src/user.zig | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/user.zig b/src/user.zig index 607776a..371460a 100644 --- a/src/user.zig +++ b/src/user.zig @@ -7,9 +7,9 @@ const ArrayList = std.ArrayList; const math = std.math; const mem = std.mem; -// ShellIndexProto is a function prototype that, given a shell's index (in +// ShellIndexFn is a function prototype that, given a shell's index (in // global shell section), will return a shell string. Matches ShelReader.get. -const ShellIndexProto = fn (u6) []const u8; +const ShellIndexFn = fn (u6) []const u8; // User is a convenient public struct for record construction and // serialization. Iterator can help retrieve these records. @@ -55,10 +55,6 @@ pub const PackedUser = struct { return @as(u32, self.name_len) + 1; } - fn gecosLen(self: *const Inner) usize { - return self.gecos_len; - } - fn gecosStart(self: *const Inner) usize { if (self.name_is_a_suffix) { return self.homeLen(); @@ -67,6 +63,10 @@ pub const PackedUser = struct { } } + fn gecosLen(self: *const Inner) usize { + return self.gecos_len; + } + fn maybeShellStart(self: *const Inner) usize { assert(self.shell_here); return self.gecosStart() + self.gecosLen(); @@ -85,7 +85,6 @@ pub const PackedUser = struct { if (self.shell_here) { result += self.shellLen(); } - return result; } }; @@ -143,7 +142,11 @@ pub const PackedUser = struct { // packTo packs the User record and copies it to the given byte slice. The // slice must have at least maxRecordSize() bytes available. // The slice is passed as a pointer, so it can be mutated. - pub fn packTo(buf: *[]u8, user: User, shellIndexFn: shellIndexFnType) error{InvalidRecord}!void { + pub fn packTo( + buf: *[]u8, + user: User, + shellIndexFn: shellIndexFnType, + ) error{InvalidRecord}!void { // function arguments are consts. We need to mutate the underlying // slice, so passing it via pointer instead. const home_len = try downCast(u6, user.home.len - 1); @@ -236,26 +239,26 @@ pub const PackedUser = struct { return self.userdata[gecos_pos .. gecos_pos + gecos_len]; } - pub fn shell(self: *const PackedUser, shellIndex: ShellIndexProto) []const u8 { + pub fn shell(self: *const PackedUser, idxFn: ShellIndexFn) []const u8 { if (self.inner.shell_here) { const shell_pos = self.inner.maybeShellStart(); const shell_len = self.inner.shellLen(); return self.userdata[shell_pos .. shell_pos + shell_len]; } - return shellIndex(self.inner.shell_len_or_idx); + return idxFn(self.inner.shell_len_or_idx); } }; -pub fn userIterator(section: []const u8, shellIndex: ShellIndexProto) Iterator { +pub fn userIterator(section: []const u8, idxFn: ShellIndexFn) Iterator { return Iterator{ .section = section, - .shellIndex = shellIndex, + .shellIndex = idxFn, }; } pub const Iterator = struct { section: ?[]const u8, - shellIndex: ShellIndexProto, + shellIndex: ShellIndexFn, pub fn next(it: *Iterator) ?PackedUser { if (it.section) |section| {