Reputation: 21
I am new in rust and trying to rewrite example of https://kernel.org/doc/html/v4.19/input/uinput.html in rust using nix crate. But at already first ioctl() in C I have problem to find analog macro in nix::ioctl. I mean this one:
ioctl(fd, UI_SET_EVBIT, EV_KEY);
What could be a solution for this one?
Upvotes: 2
Views: 76
Reputation: 23443
The nix
crate doesn't allow you to call ioctl
directly. Instead it offers macros to create wrappers around ioctl
calls, then you can call these wrappers.
UI_SET_EVBIT
is defined in linux/uinput.h
as:
#define UINPUT_IOCTL_BASE 'U'
#define UI_SET_EVBIT _IOW(UINPUT_IOCTL_BASE, 100, int)
which translate as:
const UINPUT_IOCTL_BASE: u8 = b'U'; // Defined in linux/uinput.h
ioctl_write_int!(ui_set_evbit, UINPUT_IOCTL_BASE, 100);
and you can now call the ui_set_evbit
function like this:
const EV_KEY: nix::sys::ioctl::ioctl_param_type = 1; // Defined in linux/input-event-codes.h
unsafe ui_set_evbit (EV_KEY).unwrap();
Upvotes: 4