Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/io/hidraw.zig
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ pub const HidrawDevice = struct {
if (self.wedge) |w| w.beginWrite();
defer if (self.wedge) |w| w.endWrite();
const rc = linux.ioctl(self.fd, req, @intFromPtr(data.ptr));
if (rc < 0) {
const errno = posix.errno(rc);
const errno = linux.E.init(rc);
if (errno != .SUCCESS) {
if (errno == .NODEV or errno == .PIPE) return DeviceIO.WriteError.Disconnected;
return DeviceIO.WriteError.Io;
}
Expand Down Expand Up @@ -572,3 +572,19 @@ test "hidraw: discoverWithRoot — nonexistent root returns NotFound for both nu
const err3 = HidrawDevice.discoverWithRoot(allocator, 0x37d7, 0x2401, 0, "/nonexistent_hidraw_xyz");
try std.testing.expectError(error.NotFound, err3);
}

// featureReport must surface HIDIOCSFEATURE failures. An invalid fd makes the
// ioctl return EBADF → WriteError.Io.
// Falsifiability: the old `if (rc < 0)` guard never triggered (linux.ioctl returns
// usize, never < 0), so featureReport returned void on failure and this fails.
test "hidraw: featureReport surfaces ioctl errno as error" {
var dev = HidrawDevice{
.fd = -1,
.evdev_fds = .{},
.allocator = std.testing.allocator,
};
const dev_io = dev.deviceIO();

const payload = [_]u8{ 0x01, 0x02, 0x03 };
try std.testing.expectError(DeviceIO.WriteError.Io, dev_io.featureReport(&payload));
}
Loading