Skip to content

Commit

Permalink
fix: flush success despite failure on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
mochalins committed Feb 5, 2025
1 parent 5ff880a commit 5ec21e3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/backend/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,27 @@ pub fn flush(port: std.fs.File, options: serialport.FlushOptions) !void {
else
TCOFLUSH,
);
return switch (std.posix.errno(result)) {
// Use `linux.E.init` rather than `std.posix.errno`, as `std.posix.errno`
// abstraction will not be set by syscall if libc is linked
return switch (linux.E.init(result)) {
.SUCCESS => {},
.BADF => error.FileNotFound,
.NOTTY => error.FileNotTty,
else => unreachable,
};
}

test "flush error handling" {
var f: std.fs.File = try std.fs.cwd().createFile("temp.txt", .{});
defer std.fs.cwd().deleteFile("temp.txt") catch {};
defer f.close();

try std.testing.expectError(
error.FileNotTty,
flush(f, .{ .input = true, .output = true }),
);
}

pub fn poll(port: std.fs.File) !bool {
var pollfds: [1]linux.pollfd = .{.{
.fd = port.handle,
Expand Down

0 comments on commit 5ec21e3

Please sign in to comment.