wip State.zig

This commit is contained in:
Motiejus Jakštys 2022-04-20 05:41:11 +03:00 committed by Motiejus Jakštys
parent 473e75a3f9
commit 2205d6c4b2
4 changed files with 33 additions and 37 deletions

View File

@ -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 },
};

15
lib/State.zig Normal file
View File

@ -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;

View File

@ -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
};

View File

@ -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");
}