style
This commit is contained in:
parent
9487194c95
commit
e54c153dd8
|
@ -61,7 +61,7 @@ pub const ShellWriter = struct {
|
||||||
};
|
};
|
||||||
var fullOffset: u12 = 0;
|
var fullOffset: u12 = 0;
|
||||||
var idx: u6 = 0;
|
var idx: u6 = 0;
|
||||||
while (idx < shells.len) {
|
while (idx < shells.len) : (idx += 1) {
|
||||||
const len = @intCast(u6, shells.get(idx).len);
|
const len = @intCast(u6, shells.get(idx).len);
|
||||||
try self.blob.appendSlice(shells.get(idx));
|
try self.blob.appendSlice(shells.get(idx));
|
||||||
const ourShell = self.blob.constSlice()[fullOffset .. fullOffset + len];
|
const ourShell = self.blob.constSlice()[fullOffset .. fullOffset + len];
|
||||||
|
@ -77,7 +77,6 @@ pub const ShellWriter = struct {
|
||||||
//const stderr = std.io.getStdErr().writer();
|
//const stderr = std.io.getStdErr().writer();
|
||||||
//stderr.print("\n", .{}) catch unreachable;
|
//stderr.print("\n", .{}) catch unreachable;
|
||||||
try self.blob.appendNTimes(0, padding);
|
try self.blob.appendNTimes(0, padding);
|
||||||
idx += 1;
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -155,10 +154,9 @@ pub const ShellWriter = struct {
|
||||||
var topShells = try BoundedArray([]const u8, MaxShells).init(total);
|
var topShells = try BoundedArray([]const u8, MaxShells).init(total);
|
||||||
|
|
||||||
var i: u32 = 0;
|
var i: u32 = 0;
|
||||||
while (i < total) {
|
while (i < total) : (i += 1) {
|
||||||
const elem = deque.removeMax().shell;
|
const elem = deque.removeMax().shell;
|
||||||
topShells.set(i, elem);
|
topShells.set(i, elem);
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = ShellSections.init(self.allocator, topShells);
|
const result = ShellSections.init(self.allocator, topShells);
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub const PackedUser = packed struct {
|
||||||
name_len: u5,
|
name_len: u5,
|
||||||
gecos_len: u8,
|
gecos_len: u8,
|
||||||
};
|
};
|
||||||
const PackedUserAlignment = 3; // bits
|
const PackedUserAlignmentBits = 3;
|
||||||
|
|
||||||
pub const User = struct {
|
pub const User = struct {
|
||||||
uid: u32,
|
uid: u32,
|
||||||
|
@ -35,6 +35,7 @@ pub const UserWriter = struct {
|
||||||
// function makes tests easier, and removes the Shell dependency of this
|
// function makes tests easier, and removes the Shell dependency of this
|
||||||
// module.
|
// module.
|
||||||
const shellIndexFnType = fn ([]const u8) ?u6;
|
const shellIndexFnType = fn ([]const u8) ?u6;
|
||||||
|
|
||||||
appendTo: *ArrayList(u8),
|
appendTo: *ArrayList(u8),
|
||||||
shellIndexFn: shellIndexFnType,
|
shellIndexFn: shellIndexFnType,
|
||||||
|
|
||||||
|
@ -45,9 +46,7 @@ pub const UserWriter = struct {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const fromUserErr = error{InvalidRecord};
|
pub fn downCast(comptime T: type, n: u64) error{InvalidRecord}!T {
|
||||||
|
|
||||||
pub fn downCast(comptime T: type, n: u64) fromUserErr!T {
|
|
||||||
return std.math.cast(T, n) catch |err| switch (err) {
|
return std.math.cast(T, n) catch |err| switch (err) {
|
||||||
error.Overflow => {
|
error.Overflow => {
|
||||||
return error.InvalidRecord;
|
return error.InvalidRecord;
|
||||||
|
@ -85,7 +84,7 @@ pub const UserWriter = struct {
|
||||||
|
|
||||||
try self.appendTo.appendNTimes(0, pad.roundUpPadding(
|
try self.appendTo.appendNTimes(0, pad.roundUpPadding(
|
||||||
u64,
|
u64,
|
||||||
PackedUserAlignment,
|
PackedUserAlignmentBits,
|
||||||
self.appendTo.items.len,
|
self.appendTo.items.len,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue