Added basic test

Fixed various bugs
This commit is contained in:
Caleb Gardner
2025-07-17 03:50:09 -05:00
parent 87563e43a5
commit d6b136bc8f
13 changed files with 145 additions and 97 deletions
+5 -5
View File
@@ -17,7 +17,7 @@ const RawEntry = struct {
name: []const u8,
pub fn init(alloc: std.mem.Allocator, rdr: anytype) !RawEntry {
const fixed: [8]u8 = undefined;
var fixed: [8]u8 = undefined;
_ = try rdr.read(&fixed);
const size = std.mem.readInt(u16, fixed[6..8], .little);
const name = try alloc.alloc(u8, size + 1);
@@ -25,7 +25,7 @@ const RawEntry = struct {
return .{
.offset = std.mem.readInt(u16, fixed[0..2], .little),
.num_offset = std.mem.readInt(i16, fixed[2..4], .little),
.type = std.mem.readInt(u16, fixed[4..6], .little),
.type = @enumFromInt(std.mem.readInt(u16, fixed[4..6], .little)),
.size = size,
.name = name,
};
@@ -44,8 +44,8 @@ pub const Entry = struct {
}
};
pub fn readDirectory(alloc: std.mem.Allocator, rdr: anytype, size: u32) []Entry {
const entries: std.ArrayList(Entry) = .init(alloc);
pub fn readDirectory(alloc: std.mem.Allocator, rdr: anytype, size: u32) ![]Entry {
var entries: std.ArrayList(Entry) = .init(alloc);
errdefer entries.deinit();
var cur_red: u32 = 3; // dir size includes "." & "..", so its actual size is off by 3.
var hdr: Header = undefined;
@@ -60,7 +60,7 @@ pub fn readDirectory(alloc: std.mem.Allocator, rdr: anytype, size: u32) []Entry
entries.appendAssumeCapacity(.{
.block = hdr.block,
.offset = raw_ent.offset,
.num = hdr.num + raw_ent.num_offset,
.num = @truncate(@abs(@as(i64, hdr.num) + raw_ent.num_offset)),
.type = raw_ent.type,
.name = raw_ent.name,
});