diff --git a/lib/PackedUser.zig b/lib/PackedUser.zig index 8d41762..315bbbb 100644 --- a/lib/PackedUser.zig +++ b/lib/PackedUser.zig @@ -10,7 +10,7 @@ const fieldInfo = std.meta.fieldInfo; const pad = @import("padding.zig"); const validate = @import("validate.zig"); const compress = @import("compress.zig"); -const shellImport = @import("shell.zig"); +const ShellReader = @import("shell.zig").ShellReader; const InvalidRecord = validate.InvalidRecord; const User = @import("User.zig"); @@ -114,7 +114,7 @@ pub fn fromBytes(bytes: []const u8) Entry { pub const Iterator = struct { section: ?[]const u8, - shell_reader: shellImport.ShellReader, + shell_reader: ShellReader, pub fn next(it: *Iterator) ?PackedUser { if (it.section) |section| { @@ -126,7 +126,7 @@ pub const Iterator = struct { } }; -pub fn iterator(section: []const u8, shell_reader: shellImport.ShellReader) Iterator { +pub fn iterator(section: []const u8, shell_reader: ShellReader) Iterator { return Iterator{ .section = section, .shell_reader = shell_reader }; } @@ -200,7 +200,7 @@ pub fn gecos(self: PackedUser) []const u8 { return self.bytes[gecos_pos .. gecos_pos + gecos_len]; } -pub fn shell(self: PackedUser, shell_reader: shellImport.ShellReader) []const u8 { +pub fn shell(self: PackedUser, shell_reader: ShellReader) []const u8 { if (self.inner.shell_here) { const shell_pos = self.inner.maybeShellStart(); const shell_len = self.inner.shellLen(); @@ -231,7 +231,7 @@ fn testShellIndex(allocator: Allocator) StringHashMap(u8) { return result; } -const test_shell_reader = shellImport.ShellReader{ +const test_shell_reader = ShellReader{ .blob = "/bin/bash/bin/zsh", .index = &[_]u16{ 0, 9, 17 }, }; diff --git a/lib/State.zig b/lib/State.zig new file mode 100644 index 0000000..465f1a1 --- /dev/null +++ b/lib/State.zig @@ -0,0 +1,15 @@ +const std = @import("std"); +const os = std.os; + +const DB = @import("DB.zig"); +const PackedUser = @import("PackedUser.zig"); + +// State is a type of the global variable holding the process state: +// the DB handle and all the iterators. +const State = struct { + DB: *const DB, + getpwent_iterator: *PackedUser.Iterator, +}; + +// state is initialized on library startup. +var state: State = undefined; diff --git a/lib/so.zig b/lib/so.zig deleted file mode 100644 index a5c31c5..0000000 --- a/lib/so.zig +++ /dev/null @@ -1,20 +0,0 @@ -const Passwd = extern struct { - // zig fmt: off - pw_name: [*:0]u8, // username - pw_passwd: [*:0]const u8 = "*", // user password, always '*' - pw_uid: u32, // user ID - pw_gid: u32, // group ID - pw_gecos: [*:0]const u8, // user information - pw_dir: [*:0]const u8, // home directory - pw_shell: [*:0]const u8, // shell program - // zig fmt: on -}; - -const Group = extern struct { - // zig fmt: off - gr_name: [*:0]u8, // group name - gr_passwd: [*:0]u8 = "*", // group password, always '*' - gr_gid: u32, // group ID - gr_mem: [*:0][*:0] const u8, // NULL-terminated array of pointers to group members - // zig fmt: off -}; diff --git a/lib/test_all.zig b/lib/test_all.zig index 4fda0a1..990a59f 100644 --- a/lib/test_all.zig +++ b/lib/test_all.zig @@ -1,15 +1,16 @@ test "turbonss test suite" { - _ = @import("header.zig"); - _ = @import("so.zig"); - _ = @import("DB.zig"); - _ = @import("Corpus.zig"); - _ = @import("shell.zig"); - _ = @import("User.zig"); - _ = @import("PackedUser.zig"); - _ = @import("Group.zig"); - _ = @import("validate.zig"); - _ = @import("padding.zig"); - _ = @import("compress.zig"); - _ = @import("cmph.zig"); _ = @import("bdz.zig"); + _ = @import("cmph.zig"); + _ = @import("compress.zig"); + _ = @import("Corpus.zig"); + _ = @import("DB.zig"); + _ = @import("Group.zig"); + _ = @import("header.zig"); + _ = @import("PackedGroup.zig"); + _ = @import("PackedUser.zig"); + _ = @import("padding.zig"); + _ = @import("shell.zig"); + _ = @import("State.zig"); + _ = @import("User.zig"); + _ = @import("validate.zig"); }