Skip to content

Commit

Permalink
Merge pull request Smithay#6 from sjoerdsimons/switch-to-std-io-error
Browse files Browse the repository at this point in the history
Switch to std::io::{Error,Result}
  • Loading branch information
Drakulix authored Jan 23, 2020
2 parents 8a1b34e + 484ad6a commit 52c7ad9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 89 deletions.
3 changes: 2 additions & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::str;

use std::ffi::{CStr, OsStr};
use std::io::Result;
use std::path::Path;
use std::ptr;
use std::str::FromStr;
Expand All @@ -9,7 +10,7 @@ use libc::{c_char, dev_t};

use {ffi, util};

use {FromRaw, Result};
use FromRaw;

/// A structure that provides access to sysfs/kernel devices.
pub struct Device {
Expand Down
3 changes: 2 additions & 1 deletion src/enumerator.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::ffi::OsStr;
use std::io::Result;
use std::path::Path;
use std::ptr;

use {ffi, util};

use {AsRaw, Device, FromRaw, Result};
use {AsRaw, Device, FromRaw};

/// An enumeration context.
///
Expand Down
77 changes: 0 additions & 77 deletions src/error.rs

This file was deleted.

4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ extern crate libudev_sys as ffi;

pub use device::{Attribute, Attributes, Device, Properties, Property};
pub use enumerator::{Devices, Enumerator};
pub use error::{Error, Kind as ErrorKind, Result};
pub use monitor::{Builder as MonitorBuilder, Event, EventType, Socket as MonitorSocket};

macro_rules! try_alloc {
($exp:expr) => {{
let ptr = $exp;

if ptr.is_null() {
return Err(::error::from_errno(::libc::ENOMEM));
return Err(std::io::Error::last_os_error());
}

ptr
Expand Down Expand Up @@ -72,6 +71,5 @@ macro_rules! as_ffi {

mod device;
mod enumerator;
mod error;
mod monitor;
mod util;
3 changes: 2 additions & 1 deletion src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ use std::fmt;
use std::ptr;

use std::ffi::OsStr;
use std::io::Result;
use std::ops::Deref;
use std::os::unix::io::{AsRawFd, RawFd};

use {ffi, util};

use {AsRaw, Device, FromRaw, Result};
use {AsRaw, Device, FromRaw};

/// Monitors for device events.
///
Expand Down
9 changes: 3 additions & 6 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use std::ffi::{CString, OsStr};
use std::io::Result;
use std::slice;

use libc::{c_char, c_int};

use std::os::unix::prelude::*;

use error;

use Result;

pub fn ptr_to_os_str<'a>(ptr: *const c_char) -> Option<&'a OsStr> {
if ptr.is_null() {
return None;
Expand All @@ -27,13 +24,13 @@ pub unsafe fn ptr_to_os_str_unchecked<'a>(ptr: *const c_char) -> &'a OsStr {
pub fn os_str_to_cstring<T: AsRef<OsStr>>(s: T) -> Result<CString> {
match CString::new(s.as_ref().as_bytes()) {
Ok(s) => Ok(s),
Err(_) => Err(error::from_errno(libc::EINVAL)),
Err(_) => Err(std::io::Error::from_raw_os_error(libc::EINVAL)),
}
}

pub fn errno_to_result(errno: c_int) -> Result<()> {
match errno {
0 => Ok(()),
e => Err(error::from_errno(e)),
e => Err(std::io::Error::from_raw_os_error(e)),
}
}

0 comments on commit 52c7ad9

Please sign in to comment.