Function nc::dup2 [−][src]
Expand description
Create a copy of the file descriptor oldfd
, using the speficified file
descriptor newfd
.
let path = "/tmp/nc-dup2-file";
let fd = nc::openat(nc::AT_FDCWD, path, nc::O_CREAT | nc::O_WRONLY | nc::O_TRUNC, 0o644);
assert!(fd.is_ok());
let fd = fd.unwrap();
let newfd = 8;
assert!(nc::dup2(fd, newfd).is_ok());
assert!(nc::close(fd).is_ok());
assert!(nc::close(newfd).is_ok());
assert!(nc::unlinkat(nc::AT_FDCWD, path, 0).is_ok());