Fix infinite loop when reading config file on Zig 0.15.2

Works around Zig issue https://github.com/ziglang/zig/issues/25664

Fixes #266
This commit is contained in:
Yorhel 2025-10-23 11:26:59 +02:00
parent 14bb8d0dd1
commit f452244576

View file

@ -231,9 +231,18 @@ pub const LineReader = if (@hasDecl(std.io, "bufferedReader")) struct {
}
pub fn read(s: *@This()) !?[]u8 {
return s.rd.interface.takeDelimiterExclusive('\n') catch |err| switch (err) {
error.EndOfStream => null,
// Avoid takeDelimiterExclusive() for now, it's bugged in 0.15.2: https://github.com/ziglang/zig/issues/25664
const r = &s.rd.interface;
const result = r.peekDelimiterInclusive('\n') catch |err| switch (err) {
error.EndOfStream => {
const remaining = r.buffer[r.seek..r.end];
if (remaining.len == 0) return null;
r.toss(remaining.len);
return remaining;
},
else => |e| return e,
};
r.toss(result.len);
return result[0 .. result.len - 1];
}
};