33 lines
1.0 KiB
Zig
33 lines
1.0 KiB
Zig
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
|
|
name: []const u8,
|
|
// 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,
|
|
.name = self.name.ptr,
|
|
.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,
|
|
};
|