67
67
//! # use std::mem;
68
68
//! # use nix::{Errno, libc, Result};
69
69
//! # 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> {
71
71
//! let res = libc::ioctl(fd, ior!(SPI_IOC_MAGIC, 1, mem::size_of::<u8>()), data);
72
72
//! Errno::result(res)
73
73
//! }
113
113
//! The generated function has the same form as that generated by `read`:
114
114
//!
115
115
//! ```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>;
117
117
//! ```
118
118
//!
119
119
//! There is also a `bad none`, `bad write`, and `bad readwrite` form that work similar to the
156
156
//! # pub struct spi_ioc_transfer {
157
157
//! # field1: u64,
158
158
//! # }
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);
161
161
//! Errno::result(res)
162
162
//! }
163
163
//! # fn main() {}
@@ -209,7 +209,7 @@ macro_rules! ioctl {
209
209
) ;
210
210
( bad read $name: ident with $nr: expr; $ty: ty) => (
211
211
pub unsafe fn $name( fd: $crate:: libc:: c_int,
212
- data: * mut $ty)
212
+ data: & mut $ty)
213
213
-> $crate:: Result <$crate:: libc:: c_int> {
214
214
convert_ioctl_res!( $crate:: libc:: ioctl( fd, $nr as $crate:: sys:: ioctl:: ioctl_num_type, data) )
215
215
}
@@ -223,7 +223,7 @@ macro_rules! ioctl {
223
223
) ;
224
224
( bad readwrite $name: ident with $nr: expr; $ty: ty) => (
225
225
pub unsafe fn $name( fd: $crate:: libc:: c_int,
226
- data: * mut $ty)
226
+ data: & mut $ty)
227
227
-> $crate:: Result <$crate:: libc:: c_int> {
228
228
convert_ioctl_res!( $crate:: libc:: ioctl( fd, $nr as $crate:: sys:: ioctl:: ioctl_num_type, data) )
229
229
}
@@ -236,7 +236,7 @@ macro_rules! ioctl {
236
236
) ;
237
237
( read $name: ident with $ioty: expr, $nr: expr; $ty: ty) => (
238
238
pub unsafe fn $name( fd: $crate:: libc:: c_int,
239
- data: * mut $ty)
239
+ data: & mut $ty)
240
240
-> $crate:: Result <$crate:: libc:: c_int> {
241
241
convert_ioctl_res!( $crate:: libc:: ioctl( fd, ior!( $ioty, $nr, :: std:: mem:: size_of:: <$ty>( ) ) as $crate:: sys:: ioctl:: ioctl_num_type, data) )
242
242
}
@@ -250,33 +250,30 @@ macro_rules! ioctl {
250
250
) ;
251
251
( readwrite $name: ident with $ioty: expr, $nr: expr; $ty: ty) => (
252
252
pub unsafe fn $name( fd: $crate:: libc:: c_int,
253
- data: * mut $ty)
253
+ data: & mut $ty)
254
254
-> $crate:: Result <$crate:: libc:: c_int> {
255
255
convert_ioctl_res!( $crate:: libc:: ioctl( fd, iorw!( $ioty, $nr, :: std:: mem:: size_of:: <$ty>( ) ) as $crate:: sys:: ioctl:: ioctl_num_type, data) )
256
256
}
257
257
) ;
258
258
( read buf $name: ident with $ioty: expr, $nr: expr; $ty: ty) => (
259
259
pub unsafe fn $name( fd: $crate:: libc:: c_int,
260
- data: * mut $ty,
261
- len: usize )
260
+ data: & mut [ $ty] )
262
261
-> $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) )
264
263
}
265
264
) ;
266
265
( write buf $name: ident with $ioty: expr, $nr: expr; $ty: ty) => (
267
266
pub unsafe fn $name( fd: $crate:: libc:: c_int,
268
- data: * const $ty,
269
- len: usize )
267
+ data: & [ $ty] )
270
268
-> $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) )
272
270
}
273
271
) ;
274
272
( readwrite buf $name: ident with $ioty: expr, $nr: expr; $ty: ty) => (
275
273
pub unsafe fn $name( fd: $crate:: libc:: c_int,
276
- data: * mut $ty,
277
- len: usize )
274
+ data: & mut [ $ty] )
278
275
-> $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) )
280
277
}
281
278
) ;
282
279
}
0 commit comments