|
197 | 197 | //! of lines defining macros which use `_IO`, `_IOR`, `_IOW`, `_IOC`, and `_IORW`. Some `ioctl`s are
|
198 | 198 | //! documented directly in the headers defining their constants, but others have more extensive
|
199 | 199 | //! documentation in man pages (like termios' `ioctl`s which are in `tty_ioctl(4)`).
|
| 200 | +//! |
| 201 | +//! Documenting the generated functions |
| 202 | +//! =================================== |
| 203 | +//! |
| 204 | +//! In many cases, users will wish for the functions generated by the `ioctl` |
| 205 | +//! macro to be public and documented. For this reason, the generated functions |
| 206 | +//! are public by default. If you wish to hide the ioctl, you will need to put |
| 207 | +//! them in a private module. |
| 208 | +//! |
| 209 | +//! For documentation, it is possible to use doc comments inside the `ioctl!` |
| 210 | +//! macro. Here is an example : |
| 211 | +//! |
| 212 | +//! ``` |
| 213 | +//! # #[macro_use] extern crate nix; |
| 214 | +//! # use nix::libc::c_int; |
| 215 | +//! ioctl! { |
| 216 | +//! /// Make the given terminal the controlling terminal of the calling process. The calling |
| 217 | +//! /// process must be a session leader and not have a controlling terminal already. If the |
| 218 | +//! /// terminal is already the controlling terminal of a different session group then the |
| 219 | +//! /// ioctl will fail with **EPERM**, unless the caller is root (more precisely: has the |
| 220 | +//! /// **CAP_SYS_ADMIN** capability) and arg equals 1, in which case the terminal is stolen |
| 221 | +//! /// and all processes that had it as controlling terminal lose it. |
| 222 | +//! read tiocsctty with b't', 19; c_int |
| 223 | +//! } |
| 224 | +//! |
| 225 | +//! # fn main() {} |
| 226 | +//! ``` |
| 227 | +//! |
200 | 228 | #[cfg(any(target_os = "linux", target_os = "android"))]
|
201 | 229 | #[path = "platform/linux.rs"]
|
202 | 230 | #[macro_use]
|
@@ -228,89 +256,102 @@ macro_rules! convert_ioctl_res {
|
228 | 256 | /// Generates ioctl functions. See [::sys::ioctl](sys/ioctl/index.html).
|
229 | 257 | #[macro_export]
|
230 | 258 | macro_rules! ioctl {
|
231 |
| - (bad none $name:ident with $nr:expr) => ( |
| 259 | + ($(#[$attr:meta])* bad none $name:ident with $nr:expr) => ( |
| 260 | + $(#[$attr])* |
232 | 261 | pub unsafe fn $name(fd: $crate::libc::c_int)
|
233 | 262 | -> $crate::Result<$crate::libc::c_int> {
|
234 | 263 | convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type))
|
235 | 264 | }
|
236 | 265 | );
|
237 |
| - (bad read $name:ident with $nr:expr; $ty:ty) => ( |
| 266 | + ($(#[$attr:meta])* bad read $name:ident with $nr:expr; $ty:ty) => ( |
| 267 | + $(#[$attr])* |
238 | 268 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
239 | 269 | data: *mut $ty)
|
240 | 270 | -> $crate::Result<$crate::libc::c_int> {
|
241 | 271 | convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type, data))
|
242 | 272 | }
|
243 | 273 | );
|
244 |
| - (bad write_ptr $name:ident with $nr:expr; $ty:ty) => ( |
| 274 | + ($(#[$attr:meta])* bad write_ptr $name:ident with $nr:expr; $ty:ty) => ( |
| 275 | + $(#[$attr])* |
245 | 276 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
246 | 277 | data: *const $ty)
|
247 | 278 | -> $crate::Result<$crate::libc::c_int> {
|
248 | 279 | convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type, data))
|
249 | 280 | }
|
250 | 281 | );
|
251 |
| - (bad write_int $name:ident with $nr:expr) => ( |
| 282 | + ($(#[$attr:meta])* bad write_int $name:ident with $nr:expr) => ( |
| 283 | + $(#[$attr])* |
252 | 284 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
253 | 285 | data: $crate::libc::c_int)
|
254 | 286 | -> $crate::Result<$crate::libc::c_int> {
|
255 | 287 | convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type, data))
|
256 | 288 | }
|
257 | 289 | );
|
258 |
| - (bad readwrite $name:ident with $nr:expr; $ty:ty) => ( |
| 290 | + ($(#[$attr:meta])* bad readwrite $name:ident with $nr:expr; $ty:ty) => ( |
| 291 | + $(#[$attr])* |
259 | 292 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
260 | 293 | data: *mut $ty)
|
261 | 294 | -> $crate::Result<$crate::libc::c_int> {
|
262 | 295 | convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type, data))
|
263 | 296 | }
|
264 | 297 | );
|
265 |
| - (none $name:ident with $ioty:expr, $nr:expr) => ( |
| 298 | + ($(#[$attr:meta])* none $name:ident with $ioty:expr, $nr:expr) => ( |
| 299 | + $(#[$attr])* |
266 | 300 | pub unsafe fn $name(fd: $crate::libc::c_int)
|
267 | 301 | -> $crate::Result<$crate::libc::c_int> {
|
268 | 302 | convert_ioctl_res!($crate::libc::ioctl(fd, io!($ioty, $nr) as $crate::sys::ioctl::ioctl_num_type))
|
269 | 303 | }
|
270 | 304 | );
|
271 |
| - (read $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 305 | + ($(#[$attr:meta])* read $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 306 | + $(#[$attr])* |
272 | 307 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
273 | 308 | data: *mut $ty)
|
274 | 309 | -> $crate::Result<$crate::libc::c_int> {
|
275 | 310 | convert_ioctl_res!($crate::libc::ioctl(fd, ior!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
|
276 | 311 | }
|
277 | 312 | );
|
278 |
| - (write_ptr $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 313 | + ($(#[$attr:meta])* write_ptr $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 314 | + $(#[$attr])* |
279 | 315 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
280 | 316 | data: *const $ty)
|
281 | 317 | -> $crate::Result<$crate::libc::c_int> {
|
282 | 318 | convert_ioctl_res!($crate::libc::ioctl(fd, iow!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
|
283 | 319 | }
|
284 | 320 | );
|
285 |
| - (write_int $name:ident with $ioty:expr, $nr:expr) => ( |
| 321 | + ($(#[$attr:meta])* write_int $name:ident with $ioty:expr, $nr:expr) => ( |
| 322 | + $(#[$attr])* |
286 | 323 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
287 | 324 | data: $crate::libc::c_int)
|
288 | 325 | -> $crate::Result<$crate::libc::c_int> {
|
289 | 326 | convert_ioctl_res!($crate::libc::ioctl(fd, iow!($ioty, $nr, ::std::mem::size_of::<$crate::libc::c_int>()) as $crate::sys::ioctl::ioctl_num_type, data))
|
290 | 327 | }
|
291 | 328 | );
|
292 |
| - (readwrite $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 329 | + ($(#[$attr:meta])* readwrite $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 330 | + $(#[$attr])* |
293 | 331 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
294 | 332 | data: *mut $ty)
|
295 | 333 | -> $crate::Result<$crate::libc::c_int> {
|
296 | 334 | convert_ioctl_res!($crate::libc::ioctl(fd, iorw!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data))
|
297 | 335 | }
|
298 | 336 | );
|
299 |
| - (read_buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 337 | + ($(#[$attr:meta])* read_buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 338 | + $(#[$attr])* |
300 | 339 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
301 | 340 | data: &mut [$ty])
|
302 | 341 | -> $crate::Result<$crate::libc::c_int> {
|
303 | 342 | 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))
|
304 | 343 | }
|
305 | 344 | );
|
306 |
| - (write_buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 345 | + ($(#[$attr:meta])* write_buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 346 | + $(#[$attr])* |
307 | 347 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
308 | 348 | data: &[$ty])
|
309 | 349 | -> $crate::Result<$crate::libc::c_int> {
|
310 | 350 | 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))
|
311 | 351 | }
|
312 | 352 | );
|
313 |
| - (readwrite_buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 353 | + ($(#[$attr:meta])* readwrite_buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( |
| 354 | + $(#[$attr])* |
314 | 355 | pub unsafe fn $name(fd: $crate::libc::c_int,
|
315 | 356 | data: &mut [$ty])
|
316 | 357 | -> $crate::Result<$crate::libc::c_int> {
|
|
0 commit comments