pub unsafe fn ioctl(fd: i32, cmd: i32, arg: usize) -> Result<(), Errno>
Expand description
Control device.
§Example
let path = "/tmp/nc-ioctl";
let ret = unsafe { nc::openat(nc::AT_FDCWD, path, nc::O_WRONLY | nc::O_CREAT, 0o644) };
assert!(ret.is_ok());
let fd = ret.unwrap();
let mut attr: i32 = 0;
let cmd = -2146933247; // nc::FS_IOC_GETFLAGS
let ret = unsafe { nc::ioctl(fd, cmd, &mut attr as *mut i32 as usize) };
assert!(ret.is_ok());
println!("attr: {}", attr);
let ret = unsafe { nc::close(fd) };
assert!(ret.is_ok());
let ret = unsafe { nc::unlinkat(nc::AT_FDCWD, path, 0) };
assert!(ret.is_ok());
Examples found in repository?
examples/pty.rs (line 9)
5 6 7 8 9 10 11 12 13 14 15 16 17
fn ptsname(pty_fd: i32) -> Result<String, nc::Errno> {
#[allow(unused_mut)]
let mut n: i32 = 0;
let n_ptr = (&mut n) as *mut i32 as usize;
unsafe { nc::ioctl(pty_fd, nc::TIOCGPTN, n_ptr)? };
Ok(format!("/dev/pts/{}", n))
}
fn unlockpt(pty_fd: i32) -> Result<(), nc::Errno> {
let u: i32 = 0;
let u_ptr = &u as *const i32 as usize;
unsafe { nc::ioctl(pty_fd, nc::TIOCSPTLCK, u_ptr) }
}