Function nix::unistd::mkstemp[][src]

pub fn mkstemp<P: ?Sized + NixPath>(template: &P) -> Result<(RawFd, PathBuf)>

Creates a regular file which persists even after process termination

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