From 9e80d6676b5ba29c6504a71b2a337c7c5a16957e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Tue, 19 Apr 2022 10:46:02 +0300 Subject: [PATCH] move CGroup to Group --- lib/DB.zig | 2 +- lib/Group.zig | 18 ++++++++++++++++-- lib/cgroup.zig | 15 --------------- lib/header.zig | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) delete mode 100644 lib/cgroup.zig diff --git a/lib/DB.zig b/lib/DB.zig index 0a94175..31f86ca 100644 --- a/lib/DB.zig +++ b/lib/DB.zig @@ -16,8 +16,8 @@ const pad = @import("padding.zig"); const compress = @import("compress.zig"); const PackedUser = @import("PackedUser.zig"); const User = @import("User.zig"); -const CGroup = @import("cgroup.zig").CGroup; const Group = @import("Group.zig"); +const CGroup = Group.CGroup; const PackedGroup = @import("PackedGroup.zig"); const GroupStored = PackedGroup.GroupStored; const ShellSections = @import("shell.zig").ShellWriter.ShellSections; diff --git a/lib/Group.zig b/lib/Group.zig index e43ac8f..57961f7 100644 --- a/lib/Group.zig +++ b/lib/Group.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const ptr_size = @import("cgroup.zig").ptr_size; const mem = std.mem; const meta = std.meta; @@ -56,7 +55,8 @@ pub fn deinit(self: *Group, allocator: Allocator) void { self.* = undefined; } -// buffer size in bytes if all strings were zero-terminated. +// suggested buffer size in bytes if all strings were zero-terminated +// (for CGroup). pub fn strlenZ(self: *const Group) usize { var count: usize = 0; for (self.members) |member| @@ -66,6 +66,20 @@ pub fn strlenZ(self: *const Group) usize { return count; } +// Name type should be 0-terminated, members should be null-terminated, but +// sentinel is not part of the type (but is always there). Adding sentinel +// crashes zig compiler in pre-0.10. https://github.com/ziglang/zig/issues/7517 +pub const CGroup = extern struct { + gid: u32, + // should be [*:0]const u8 + name: [*]const u8, + // Should be [*:null]align(1) const ?[*:0]const u8 + members: [*]align(1) const ?[*:0]const u8, +}; + +// size of the pointer to a single member. +pub const ptr_size = @sizeOf(meta.Child(meta.fieldInfo(CGroup, .members).field_type)); + const testing = std.testing; test "Group.clone" { diff --git a/lib/cgroup.zig b/lib/cgroup.zig deleted file mode 100644 index 31bc05d..0000000 --- a/lib/cgroup.zig +++ /dev/null @@ -1,15 +0,0 @@ -const meta = @import("std").meta; - -// Name type should be 0-terminated, members should be null-terminated, but -// sentinel is not part of the type (but is always there). Adding sentinel -// crashes zig compiler in pre-0.10. https://github.com/ziglang/zig/issues/7517 -pub const CGroup = extern struct { - gid: u32, - // should be [*:0]const u8 - name: [*]const u8, - // Should be [*:null]align(1) const ?[*:0]const u8 - members: [*]align(1) const ?[*:0]const u8, -}; - -// size of the pointer to a single member. -pub const ptr_size = @sizeOf(meta.Child(meta.fieldInfo(CGroup, .members).field_type)); diff --git a/lib/header.zig b/lib/header.zig index 96ea7a4..2cb878c 100644 --- a/lib/header.zig +++ b/lib/header.zig @@ -2,7 +2,7 @@ const std = @import("std"); const mem = std.mem; const math = std.math; const native_endian = @import("builtin").target.cpu.arch.endian(); -const ptr_size = @import("cgroup.zig").ptr_size; +const ptr_size = @import("Group.zig").ptr_size; const max_shells = @import("shell.zig").max_shells; const magic = [4]u8{ 0xf0, 0x9f, 0xa4, 0xb7 };