From ffeec99fd75a4fe980e55a6eecb07e9cc71e70d9 Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Thu, 30 Jun 2022 10:01:54 +0800 Subject: [PATCH] evdev: wrap errors to errors::error --- cmd/pointerd/main.ha | 4 ++-- evdev/libevdev.ha | 8 ++++---- evdev/uinput/uinput.ha | 9 +++++---- tools/evdev-dump-events/main.ha | 13 ++++++------- tools/uinput-pointer/main.ha | 5 +++-- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/cmd/pointerd/main.ha b/cmd/pointerd/main.ha index ec23c22..4e3d330 100644 --- a/cmd/pointerd/main.ha +++ b/cmd/pointerd/main.ha @@ -42,8 +42,8 @@ export fn main() void = { const uinput = match (uinput::create_from_device(evdev, uinput::OPEN_MANAGED)) { case let uinput: uinput::uinput => yield uinput; - case let err: rt::errno => - fmt::fatalf("Failed to create uinput dev: {}", rt::strerror(err)); + case let err: errors::error => + fmt::fatalf("Failed to create uinput dev: {}", errors::strerror(err)); }; defer uinput::destroy(uinput); diff --git a/evdev/libevdev.ha b/evdev/libevdev.ha index 0802f0a..7aa89d5 100644 --- a/evdev/libevdev.ha +++ b/evdev/libevdev.ha @@ -3,11 +3,11 @@ use io; use rt; use strings; -export fn new_from_fd(fd: io::file) (rt::errno | libevdev) = { +export fn new_from_fd(fd: io::file) (errors::error | libevdev) = { let handle = null: libevdev; const r = c_libevdev_new_from_fd(fd, &handle); if (r < 0) { - return (-r): rt::errno; + return errors::errno(-r); }; return handle; }; @@ -22,11 +22,11 @@ export fn set_name(dev: libevdev, name: str) void = { c_libevdev_set_name(dev, cstr); }; -export fn next_event(dev: libevdev, flags: uint) (rt::errno | input_event) = { +export fn next_event(dev: libevdev, flags: uint) (errors::error | input_event) = { let ev = input_event { ... }; const r = c_libevdev_next_event(dev, flags, &ev); if (r < 0) { - return (-r): rt::errno; + return errors::errno(-r); }; return ev; }; diff --git a/evdev/uinput/uinput.ha b/evdev/uinput/uinput.ha index e8bc1a5..be6ad2f 100644 --- a/evdev/uinput/uinput.ha +++ b/evdev/uinput/uinput.ha @@ -1,22 +1,23 @@ +use errors; use evdev; use io; use rt; export fn create_from_device(dev: evdev::libevdev, fd: io::file) - (uinput | rt::errno) = { + (uinput | errors::error) = { let handle = null: uinput; const r = c_libevdev_uinput_create_from_device(dev, fd: int, &handle); if (r < 0) { - return (-r): rt::errno; + return errors::errno(-r); }; return handle; }; export fn write_event(uinput_dev: uinput, event_type: uint, code: uint, value: int) - (void | rt::errno) = { + (void | errors::error) = { const r = c_libevdev_uinput_write_event(uinput_dev, event_type, code, value); if (r < 0) { - return (-r): rt::errno; + return errors::errno(-r); }; }; diff --git a/tools/evdev-dump-events/main.ha b/tools/evdev-dump-events/main.ha index deed99b..21d9e0f 100644 --- a/tools/evdev-dump-events/main.ha +++ b/tools/evdev-dump-events/main.ha @@ -4,7 +4,6 @@ use fmt; use fs; use io; use os; -use rt; use strconv; export fn main() void = { @@ -21,8 +20,8 @@ export fn main() void = { const evdev = match (evdev::new_from_fd(file)) { case let evdev: evdev::libevdev => yield evdev; - case let err: rt::errno => - fmt::fatalf("Failed to init libevdev: {}", rt::strerror(err)); + case let err: errors::error => + fmt::fatalf("Failed to init libevdev: {}", errors::strerror(err)); }; fmt::printfln("Input device name: {}", evdev::get_name(evdev))!; @@ -31,12 +30,12 @@ export fn main() void = { let ev = match (evdev::next_event(evdev, evdev::READ_FLAG_NORMAL)) { case let ev: evdev::input_event => yield ev; - case let err: rt::errno => - switch (err) { - case rt::EAGAIN => + case let err: errors::error => + match (err) { + case errors::again => continue; case => - fmt::fatalf("Failed to get event: {}", rt::strerror(err)); + fmt::fatalf("Failed to get event: {}", errors::strerror(err)); }; }; match (evdev::event_type_get_name(ev._type)) { diff --git a/tools/uinput-pointer/main.ha b/tools/uinput-pointer/main.ha index e1b60ab..95fb6b8 100644 --- a/tools/uinput-pointer/main.ha +++ b/tools/uinput-pointer/main.ha @@ -1,3 +1,4 @@ +use errors; use evdev; use evdev::uinput; use fmt; @@ -19,8 +20,8 @@ export fn main() void = { const uinput = match (uinput::create_from_device(evdev, uinput::OPEN_MANAGED)) { case let uinput: uinput::uinput => yield uinput; - case let err: rt::errno => - fmt::fatalf("Failed to create uinput dev: {}", rt::strerror(err)); + case let err: errors::error => + fmt::fatalf("Failed to create uinput dev: {}", errors::strerror(err)); }; defer uinput::destroy(uinput); -- 2.45.2