fix user writing

This commit is contained in:
Motiejus Jakštys 2022-07-02 16:24:47 +03:00
parent 83fa0c8733
commit e79cdaffde
2 changed files with 5 additions and 4 deletions

View File

@ -103,8 +103,8 @@ const max_line_len = fmt.count(line_fmt, .{
// toLine formats the user in /etc/passwd format, including the EOL
pub fn toLine(self: *const User) BoundedArray(u8, max_line_len) {
var result = BoundedArray(u8, max_line_len).init(max_line_len) catch unreachable;
_ = fmt.bufPrint(result.slice(), line_fmt, .{
var result = BoundedArray(u8, max_line_len).init(0) catch unreachable;
result.writer().print(line_fmt, .{
self.name,
self.uid,
self.gid,

View File

@ -202,8 +202,9 @@ test "smoke test" {
var i: usize = 0;
while (i < corpus.users.len) : (i += 1) {
const user = corpus.users.get(i);
const line = user.toLine();
_ = try os.write(passwd_fd, line.constSlice());
const line = user.toLine().constSlice();
std.debug.print("({d}){s}", .{ line.len, line });
_ = try os.write(passwd_fd, line);
}
os.close(passwd_fd);