Skip to content

Commit 77372b4

Browse files
committed
Use references instead of raw pointers
1 parent 7156068 commit 77372b4

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/sys/ioctl/mod.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
//! # use std::mem;
6868
//! # use nix::{Errno, libc, Result};
6969
//! # const SPI_IOC_MAGIC: u8 = 'k' as u8;
70-
//! pub unsafe fn spi_read_mode(fd: c_int, data: *mut u8) -> Result<c_int> {
70+
//! pub unsafe fn spi_read_mode(fd: c_int, data: &mut u8) -> Result<c_int> {
7171
//! let res = libc::ioctl(fd, ior!(SPI_IOC_MAGIC, 1, mem::size_of::<u8>()), data);
7272
//! Errno::result(res)
7373
//! }
@@ -113,7 +113,7 @@
113113
//! The generated function has the same form as that generated by `read`:
114114
//!
115115
//! ```text
116-
//! pub unsafe fn tcgets(fd: c_int, val: *mut termios) -> Result<c_int>;
116+
//! pub unsafe fn tcgets(fd: c_int, val: &mut termios) -> Result<c_int>;
117117
//! ```
118118
//!
119119
//! There is also a `bad none`, `bad write`, and `bad readwrite` form that work similar to the
@@ -156,8 +156,8 @@
156156
//! # pub struct spi_ioc_transfer {
157157
//! # field1: u64,
158158
//! # }
159-
//! pub unsafe fn spi_transfer_buf(fd: c_int, data: *mut spi_ioc_transfer, len: usize) -> Result<c_int> {
160-
//! let res = libc::ioctl(fd, ior!(SPI_IOC_MAGIC, SPI_IOC_NR_TRANSFER, len * mem::size_of::<u8>()), data);
159+
//! pub unsafe fn spi_transfer_buf(fd: c_int, data: &mut [spi_ioc_transfer], len: usize) -> Result<c_int> {
160+
//! let res = libc::ioctl(fd, ior!(SPI_IOC_MAGIC, SPI_IOC_NR_TRANSFER, data.len() * mem::size_of::<u8>()), data);
161161
//! Errno::result(res)
162162
//! }
163163
//! # fn main() {}
@@ -209,7 +209,7 @@ macro_rules! ioctl {
209209
);
210210
(bad read $name:ident with $nr:expr; $ty:ty) => (
211211
pub unsafe fn $name(fd: $crate::libc::c_int,
212-
data: *mut $ty)
212+
data: &mut $ty)
213213
-> $crate::Result<$crate::libc::c_int> {
214214
convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type, data))
215215
}
@@ -223,7 +223,7 @@ macro_rules! ioctl {
223223
);
224224
(bad readwrite $name:ident with $nr:expr; $ty:ty) => (
225225
pub unsafe fn $name(fd: $crate::libc::c_int,
226-
data: *mut $ty)
226+
data: &mut $ty)
227227
-> $crate::Result<$crate::libc::c_int> {
228228
convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type, data))
229229
}
@@ -236,7 +236,7 @@ macro_rules! ioctl {
236236
);
237237
(read $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
238238
pub unsafe fn $name(fd: $crate::libc::c_int,
239-
data: *mut $ty)
239+
data: &mut $ty)
240240
-> $crate::Result<$crate::libc::c_int> {
241241
convert_ioctl_res!($crate::libc::ioctl(fd, ior!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
242242
}
@@ -250,33 +250,30 @@ macro_rules! ioctl {
250250
);
251251
(readwrite $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
252252
pub unsafe fn $name(fd: $crate::libc::c_int,
253-
data: *mut $ty)
253+
data: &mut $ty)
254254
-> $crate::Result<$crate::libc::c_int> {
255255
convert_ioctl_res!($crate::libc::ioctl(fd, iorw!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
256256
}
257257
);
258258
(read buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
259259
pub unsafe fn $name(fd: $crate::libc::c_int,
260-
data: *mut $ty,
261-
len: usize)
260+
data: &mut [$ty])
262261
-> $crate::Result<$crate::libc::c_int> {
263-
convert_ioctl_res!($crate::libc::ioctl(fd, ior!($ioty, $nr, len * ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
262+
convert_ioctl_res!($crate::libc::ioctl(fd, ior!($ioty, $nr, data.len() * ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
264263
}
265264
);
266265
(write buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
267266
pub unsafe fn $name(fd: $crate::libc::c_int,
268-
data: *const $ty,
269-
len: usize)
267+
data: &[$ty])
270268
-> $crate::Result<$crate::libc::c_int> {
271-
convert_ioctl_res!($crate::libc::ioctl(fd, iow!($ioty, $nr, len * ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
269+
convert_ioctl_res!($crate::libc::ioctl(fd, iow!($ioty, $nr, data.len() * ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
272270
}
273271
);
274272
(readwrite buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => (
275273
pub unsafe fn $name(fd: $crate::libc::c_int,
276-
data: *mut $ty,
277-
len: usize)
274+
data: &mut [$ty])
278275
-> $crate::Result<$crate::libc::c_int> {
279-
convert_ioctl_res!($crate::libc::ioctl(fd, iorw!($ioty, $nr, len * ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
276+
convert_ioctl_res!($crate::libc::ioctl(fd, iorw!($ioty, $nr, data.len() * ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
280277
}
281278
);
282279
}

0 commit comments

Comments
 (0)