diff options
author | Andreas Fuchs <asf@boinkor.net> | 2016-05-01 12:52:20 -0700 |
---|---|---|
committer | Andreas Fuchs <asf@boinkor.net> | 2016-05-01 12:52:20 -0700 |
commit | a821f9630cbe3ee12846625fa63abc768b59d1a0 (patch) | |
tree | 5ddbc096b827c5fb71e1b14dd45ba01b7a22b0ea /src/unistd.rs | |
parent | 5fa5fd49fb7c9655dc71f2bdb272cb85df317bfb (diff) | |
download | nix-a821f9630cbe3ee12846625fa63abc768b59d1a0.zip |
Add mkstemp(3)
Diffstat (limited to 'src/unistd.rs')
-rw-r--r-- | src/unistd.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/unistd.rs b/src/unistd.rs index 71448248..31367791 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -374,6 +374,19 @@ pub fn sleep(seconds: libc::c_uint) -> c_uint { unsafe { libc::sleep(seconds) } } +#[inline] +pub fn mkstemp<P: ?Sized + NixPath>(template: &P) -> Result<RawFd> { + let res = try!(template.with_nix_path(|path| { + let mut path_copy = path.to_bytes_with_nul().to_owned(); + let c_template: *mut c_char = path_copy.as_mut_ptr() as *mut c_char; + unsafe { + libc::mkstemp(c_template) + } + })); + Errno::result(res) + +} + #[cfg(any(target_os = "linux", target_os = "android"))] mod linux { use sys::syscall::{syscall, SYSPIVOTROOT}; |