summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
authorAndreas Fuchs <asf@boinkor.net>2016-05-01 12:52:20 -0700
committerAndreas Fuchs <asf@boinkor.net>2016-05-01 12:52:20 -0700
commita821f9630cbe3ee12846625fa63abc768b59d1a0 (patch)
tree5ddbc096b827c5fb71e1b14dd45ba01b7a22b0ea /src/unistd.rs
parent5fa5fd49fb7c9655dc71f2bdb272cb85df317bfb (diff)
downloadnix-a821f9630cbe3ee12846625fa63abc768b59d1a0.zip
Add mkstemp(3)
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs13
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};