rust/src/libstd/tempfile.rs
2011-12-06 13:58:54 -08:00

27 lines
455 B
Rust

/*
Module: tempfile
Temporary files and directories
*/
import fs;
import option;
import option::{none, some};
import rand;
/*
Function: mkdtemp
*/
fn mkdtemp(prefix: str, suffix: str) -> option::t<str> {
let r = rand::mk_rng();
let i = 0u;
while (i < 1000u) {
let s = prefix + r.gen_str(16u) + suffix;
if fs::make_dir(s, 0x1c0i32) { // FIXME: u+rwx
ret some(s);
}
i += 1u;
}
ret none;
}