Skip to content

Commit

Permalink
ioctl: make ioctl functions public
Browse files Browse the repository at this point in the history
Consumers of the API may control visibility by means of a module.  The
following is a useful pattern that may be used by implementors (here for
a couple of i2cdev ioctl definitions):

    mod ioctl {
        ioctl!(bad set_i2c_slave_address with super::I2C_SLAVE);
        ioctl!(bad i2c_smbus with super::I2C_SMBUS);
    }

This resolves nix-rust#184.
  • Loading branch information
posborne committed Sep 1, 2015
1 parent e528739 commit 141d369
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/sys/ioctl/platform/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,59 +95,59 @@ macro_rules! convert_ioctl_res {
#[macro_export]
macro_rules! ioctl {
(bad $name:ident with $nr:expr) => (
unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
data: *mut u8)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
pub unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
data: *mut u8)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
convert_ioctl_res!($crate::sys::ioctl::ioctl(fd, $nr as $crate::sys::ioctl::libc::c_ulong, data))
}
);
(none $name:ident with $ioty:expr, $nr:expr) => (
unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
pub unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
convert_ioctl_res!($crate::sys::ioctl::ioctl(fd, io!($ioty, $nr) as $crate::sys::ioctl::libc::c_ulong))
}
);
(read $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
val: *mut $ty)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
pub unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
val: *mut $ty)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
convert_ioctl_res!($crate::sys::ioctl::ioctl(fd, ior!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::libc::c_ulong, val))
}
);
(write $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
val: *const $ty)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
pub unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
val: *const $ty)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
convert_ioctl_res!($crate::sys::ioctl::ioctl(fd, iow!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::libc::c_ulong, val))
}
);
(readwrite $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
val: *mut $ty)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
pub unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
val: *mut $ty)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
convert_ioctl_res!($crate::sys::ioctl::ioctl(fd, iorw!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::libc::c_ulong, val))
}
);
(read buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
val: *mut $ty,
len: usize)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
pub unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
val: *mut $ty,
len: usize)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
convert_ioctl_res!($crate::sys::ioctl::ioctl(fd, ior!($ioty, $nr, len) as $crate::sys::ioctl::libc::c_ulong, val))
}
);
(write buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
val: *const $ty,
len: usize) -> $crate::Result<$crate::sys::ioctl::libc::c_int> {
pub unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
val: *const $ty,
len: usize) -> $crate::Result<$crate::sys::ioctl::libc::c_int> {
convert_ioctl_res!($crate::sys::ioctl::ioctl(fd, iow!($ioty, $nr, len) as $crate::sys::ioctl::libc::c_ulong, val))
}
);
(readwrite buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
val: *const $ty,
len: usize)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
pub unsafe fn $name(fd: $crate::sys::ioctl::libc::c_int,
val: *const $ty,
len: usize)
-> $crate::Result<$crate::sys::ioctl::libc::c_int> {
convert_ioctl_res!($crate::sys::ioctl::ioctl(fd, iorw!($ioty, $nr, len) as $crate::sys::ioctl::libc::c_ulong, val))
}
);
Expand Down

0 comments on commit 141d369

Please sign in to comment.