2022-04-19 07:18:41 +03:00
|
|
|
const meta = @import("std").meta;
|
|
|
|
|
|
|
|
// All string fields are 0-terminated, but that's not part of the type.
|
|
|
|
// members field is null-terminated, but that's also not part of the type.
|
|
|
|
// Making it part of the type crashes zig compiler in pre-0.10.
|
|
|
|
// https://github.com/ziglang/zig/issues/7517
|
|
|
|
|
|
|
|
pub const CGroup = struct {
|
|
|
|
gid: u32,
|
|
|
|
// should be [*:0]const u8
|
2022-04-19 10:24:32 +03:00
|
|
|
name: [*]const u8,
|
2022-04-19 07:18:41 +03:00
|
|
|
// Should be [*:null]align(1) const ?[*:0]const u8
|
|
|
|
members: []align(1) const ?[*:0]const u8,
|
|
|
|
|
|
|
|
pub fn ptr(self: *const CGroup) CGroupPtr {
|
|
|
|
return CGroupPtr{
|
|
|
|
.gid = self.gid,
|
2022-04-19 10:24:32 +03:00
|
|
|
.name = self.name,
|
2022-04-19 07:18:41 +03:00
|
|
|
.members = @intToPtr([*]const u8, @ptrToInt(self.members.ptr)),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// size of the pointer to a single member.
|
|
|
|
pub const ptr_size = @sizeOf(meta.Child(meta.fieldInfo(CGroup, .members).field_type));
|
|
|
|
|
|
|
|
// a workaround of not having sentinel-terminated `name` and `members`.
|
|
|
|
pub const CGroupPtr = extern struct {
|
|
|
|
gid: u32,
|
|
|
|
name: [*]const u8,
|
|
|
|
members: [*]const u8,
|
|
|
|
};
|