getgrgid
This commit is contained in:
parent
d4ba5a9a58
commit
3eeb0a8332
14
lib/DB.zig
14
lib/DB.zig
@ -276,6 +276,15 @@ fn getgrnam(self: *const DB, name: []const u8, buf: *[]u8) error{OutOfMemory}!?C
|
||||
return try self.getGroup(group, buf);
|
||||
}
|
||||
|
||||
// get a CGroup entry by it's gid.
|
||||
fn getgrgid(self: *const DB, gid: u32, buf: *[]u8) error{OutOfMemory}!?CGroup {
|
||||
const idx = bdz.search_u32(self.bdz_gid, gid);
|
||||
const offset = self.idx_gid2group[idx];
|
||||
const group = PackedGroup.fromBytes(self.groups[offset << 3 ..]).group;
|
||||
if (gid != group.gid()) return null;
|
||||
return try self.getGroup(group, buf);
|
||||
}
|
||||
|
||||
fn shellSections(
|
||||
allocator: Allocator,
|
||||
corpus: *const Corpus,
|
||||
@ -610,6 +619,11 @@ test "high-level API" {
|
||||
try testing.expectEqual(cgroup.name[1], 'l');
|
||||
try testing.expectEqual(cgroup.name[2], 'l');
|
||||
try testing.expectEqual(cgroup.name[3], 0);
|
||||
|
||||
const all_gid = try db.getgrgid(9999, &buf);
|
||||
try testing.expect(all_gid != null);
|
||||
try testing.expectEqual(all_gid.?.gid, 9999);
|
||||
try testing.expectEqualStrings(mem.sliceTo(all_gid.?.name, 0), "all");
|
||||
}
|
||||
|
||||
test "getgr_bufsize" {
|
||||
|
Loading…
Reference in New Issue
Block a user