[−][src]Function nix::unistd::mkstemp
pub fn mkstemp<P: ?Sized + NixPath>(template: &P) -> Result<(RawFd, PathBuf)>
Creates a regular file which persists even after process termination
template
: a path whose 6 rightmost characters must be X, e.g./tmp/tmpfile_XXXXXX
- returns: tuple of file descriptor and filename
Err is returned either if no temporary filename could be created or the template doesn't end with XXXXXX
See also mkstemp(2)
Example
use nix::unistd; let _ = match unistd::mkstemp("/tmp/tempfile_XXXXXX") { Ok((fd, path)) => { unistd::unlink(path.as_path()).unwrap(); // flag file to be deleted at app termination fd } Err(e) => panic!("mkstemp failed: {}", e) }; // do something with fd