1
Fork 0

CGroup.name is [*]u8 now

main
Motiejus Jakštys 2022-04-19 10:24:32 +03:00 committed by Motiejus Jakštys
parent 3eeb0a8332
commit ce827a9ae6
2 changed files with 5 additions and 5 deletions

View File

@ -261,7 +261,7 @@ fn getGroup(
buf.*[buf_offset + name.len] = 0; buf.*[buf_offset + name.len] = 0;
return CGroup{ return CGroup{
.name = buf.*[buf_offset .. buf_offset + name.len :0], .name = buf.*[buf_offset .. buf_offset + name.len].ptr,
.gid = group.gid(), .gid = group.gid(),
.members = member_ptrs, .members = member_ptrs,
}; };
@ -605,7 +605,7 @@ test "high-level API" {
const all = try db.getgrnam("all", &buf); const all = try db.getgrnam("all", &buf);
try testing.expect(all != null); try testing.expect(all != null);
try testing.expectEqual(all.?.gid, 9999); try testing.expectEqual(all.?.gid, 9999);
try testing.expectEqualStrings(mem.sliceTo(all.?.name, 0), "all"); try testing.expectEqualStrings(all.?.name[0..3], "all");
const members = all.?.members; const members = all.?.members;
try testing.expectEqualStrings(mem.sliceTo(members[0].?, 0), "Name" ** 8); try testing.expectEqualStrings(mem.sliceTo(members[0].?, 0), "Name" ** 8);
try testing.expectEqualStrings(mem.sliceTo(members[1].?, 0), "root"); try testing.expectEqualStrings(mem.sliceTo(members[1].?, 0), "root");
@ -623,7 +623,7 @@ test "high-level API" {
const all_gid = try db.getgrgid(9999, &buf); const all_gid = try db.getgrgid(9999, &buf);
try testing.expect(all_gid != null); try testing.expect(all_gid != null);
try testing.expectEqual(all_gid.?.gid, 9999); try testing.expectEqual(all_gid.?.gid, 9999);
try testing.expectEqualStrings(mem.sliceTo(all_gid.?.name, 0), "all"); try testing.expectEqualStrings(all_gid.?.name[0..3], "all");
} }
test "getgr_bufsize" { test "getgr_bufsize" {

View File

@ -8,14 +8,14 @@ const meta = @import("std").meta;
pub const CGroup = struct { pub const CGroup = struct {
gid: u32, gid: u32,
// should be [*:0]const u8 // should be [*:0]const u8
name: []const u8, name: [*]const u8,
// Should be [*:null]align(1) const ?[*:0]const u8 // Should be [*:null]align(1) const ?[*:0]const u8
members: []align(1) const ?[*:0]const u8, members: []align(1) const ?[*:0]const u8,
pub fn ptr(self: *const CGroup) CGroupPtr { pub fn ptr(self: *const CGroup) CGroupPtr {
return CGroupPtr{ return CGroupPtr{
.gid = self.gid, .gid = self.gid,
.name = self.name.ptr, .name = self.name,
.members = @intToPtr([*]const u8, @ptrToInt(self.members.ptr)), .members = @intToPtr([*]const u8, @ptrToInt(self.members.ptr)),
}; };
} }