Skip to content

Commit 0994405

Browse files
committed
WIP
1 parent ff96cd5 commit 0994405

5 files changed

Lines changed: 36 additions & 14 deletions

File tree

.github/workflows/zig-master.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
name: Zig Master Canary
22

3-
# Early-warning build against the Zig master toolchain. A failure here does not block anything;
4-
# it signals upcoming breakage (std API churn, bundled Clang changes, dependency build.zig incompatibilities)
5-
# months before the next Zig release forces an upgrade.
6-
73
on:
84
workflow_dispatch:
95
schedule: # Run every Monday at 06:00 (UTC)

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
.hash = "minish-0.3.0-SQtSTYI3AgCxWdWbKxS_lvmfbp0wJk29ZW5C9CozJaxm",
1010
},
1111
.chilli = .{
12-
.url = "https://github.com/CogitatorTech/chilli/archive/refs/tags/v0.3.1.tar.gz",
13-
.hash = "chilli-0.3.1-c19PrjizAQByQrJlXzEb8SrMY6cDJyWaZ9FnxFfN0kYl",
12+
.url = "https://github.com/CogitatorTech/chilli/archive/refs/tags/v0.3.2.tar.gz",
13+
.hash = "chilli-0.3.2-c19PrireAQAXEfA7xrmJW2lrSiNiuuG8wtJI-MJVZgFU",
1414
},
1515
.zsdl = .{
1616
.url = "https://github.com/zig-gamedev/zsdl/archive/100f46b336a112497436144e14877118573e0adf.tar.gz",

src/platform.zig

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,17 @@ pub const File = struct {
7777
return self.f.writer(io(), buffer);
7878
}
7979

80+
// std.Io.File exposes no public seek wrappers (only positional reads and
81+
// writes), so go through the Io vtable, which implements seeking for
82+
// every supported OS.
8083
pub fn seekTo(self: File, offset: u64) !void {
81-
const rc = std.os.linux.lseek(self.f.handle, @intCast(offset), std.os.linux.SEEK.SET);
82-
if (std.os.linux.errno(rc) != .SUCCESS) return error.Unseekable;
84+
const i = io();
85+
return i.vtable.fileSeekTo(i.userdata, self.f, offset);
8386
}
8487

85-
pub fn getPos(self: File) !u64 {
86-
const rc = std.os.linux.lseek(self.f.handle, 0, std.os.linux.SEEK.CUR);
87-
if (std.os.linux.errno(rc) != .SUCCESS) return error.Unseekable;
88-
return rc;
88+
pub fn seekBy(self: File, offset: i64) !void {
89+
const i = io();
90+
return i.vtable.fileSeekBy(i.userdata, self.f, offset);
8991
}
9092

9193
pub fn readToEndAlloc(self: File, allocator: std.mem.Allocator, max_bytes: usize) ![]u8 {
@@ -97,6 +99,28 @@ pub const File = struct {
9799
}
98100
};
99101

102+
test "File seekTo and seekBy reposition the stream" {
103+
var tmp = std.testing.tmpDir(.{});
104+
defer tmp.cleanup();
105+
106+
var file = try (Dir{ .d = tmp.dir }).createFile("seek.bin", .{ .read = true });
107+
defer file.close();
108+
try file.writeAll("abcdef");
109+
110+
try file.seekTo(1);
111+
var buf: [2]u8 = undefined;
112+
try std.testing.expectEqual(@as(usize, 2), try file.readAll(buf[0..2]));
113+
try std.testing.expectEqualSlices(u8, "bc", buf[0..2]);
114+
115+
try file.seekBy(-1);
116+
try std.testing.expectEqual(@as(usize, 1), try file.readAll(buf[0..1]));
117+
try std.testing.expectEqual(@as(u8, 'c'), buf[0]);
118+
119+
try file.seekTo(0);
120+
try std.testing.expectEqual(@as(usize, 1), try file.readAll(buf[0..1]));
121+
try std.testing.expectEqual(@as(u8, 'a'), buf[0]);
122+
}
123+
100124
pub fn stdout() File {
101125
return .{ .f = std.Io.File.stdout() };
102126
}

src/recording/gif.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ pub const GifRecorder = struct {
6666
if (framebuffer.len < stride * (height - 1) + width) return error.InvalidFrameSize;
6767

6868
if (self.frame_count > 0) {
69-
const pos = self.file.getPos() catch 0;
70-
if (pos > 0) self.file.seekTo(pos - 1) catch {};
69+
// Step back over the GIF trailer byte so the new frame overwrites it.
70+
self.file.seekBy(-1) catch {};
7171
}
7272

7373
var palette: [max_colors]u32 = [_]u32{0} ** max_colors;

src/unit_test_root.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const frontend_saves = @import("frontend/saves.zig");
3939
const input_gamepad = @import("input/gamepad.zig");
4040
const input_keyboard = @import("input/keyboard.zig");
4141
const libretro = @import("libretro.zig");
42+
const platform_mod = @import("platform.zig");
4243

4344
comptime {
4445
_ = audio_blip_buf;
@@ -82,4 +83,5 @@ comptime {
8283
_ = input_gamepad;
8384
_ = input_keyboard;
8485
_ = libretro;
86+
_ = platform_mod;
8587
}

0 commit comments

Comments
 (0)