1
Fork 0

move CGroup to Group

main
Motiejus Jakštys 2022-04-19 10:46:02 +03:00 committed by Motiejus Jakštys
parent be9bf3f51c
commit 9e80d6676b
4 changed files with 18 additions and 19 deletions

View File

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

View File

@ -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" {

View File

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

View File

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