Skip to content

Commit

Permalink
Hack fixes Smithay#11
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ien committed Mar 10, 2020
1 parent da07a27 commit 9dbf3bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ impl Device {
pub fn from_syspath(syspath: &Path) -> Result<Self> {
let syspath = util::os_str_to_cstring(syspath)?;

// Hack. We use this because old version libudev check udev arg by null ptr and return error
// if udev eq nullptr. In current version first argument unused
let ptr = try_alloc!(unsafe {
ffi::udev_device_new_from_syspath(ptr::null_mut(), syspath.as_ptr())
ffi::udev_device_new_from_syspath([].as_mut_ptr() as *mut ffi::udev, syspath.as_ptr())
});

Ok(unsafe { Self::from_raw(ptr) })
Expand Down
15 changes: 13 additions & 2 deletions src/enumerator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::ffi::OsStr;
use std::io::Result;
use std::path::Path;
use std::ptr;

use {ffi, util};

Expand Down Expand Up @@ -33,7 +32,9 @@ as_ffi!(Enumerator, enumerator, ffi::udev_enumerate);
impl Enumerator {
/// Creates a new Enumerator.
pub fn new() -> Result<Self> {
let ptr = try_alloc!(unsafe { ffi::udev_enumerate_new(ptr::null_mut()) });
// Hack. We use this because old version libudev check udev arg by null ptr and return error
// if udev eq nullptr. In current version first argument unused
let ptr = try_alloc!(unsafe { ffi::udev_enumerate_new([].as_mut_ptr() as *mut ffi::udev) });
Ok(unsafe { Self::from_raw(ptr) })
}

Expand Down Expand Up @@ -191,3 +192,13 @@ impl Iterator for Devices {
(0, None)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn create_enumerator() {
Enumerator::new().unwrap();
}
}
6 changes: 5 additions & 1 deletion src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ impl Builder {
pub fn new() -> Result<Self> {
let name = b"udev\0".as_ptr() as *const i8;

let ptr = try_alloc!(unsafe { ffi::udev_monitor_new_from_netlink(ptr::null_mut(), name) });
// Hack. We use this because old version libudev check udev arg by null ptr and return error
// if udev eq nullptr. In current version first argument unused
let ptr = try_alloc!(unsafe {
ffi::udev_monitor_new_from_netlink([].as_mut_ptr() as *mut ffi::udev, name)
});

Ok(unsafe { Self::from_raw(ptr) })
}
Expand Down

0 comments on commit 9dbf3bc

Please sign in to comment.