initial implementation of OpenOptions to c_int

This commit is contained in:
Federico Ponzi 2020-08-30 16:21:41 +02:00
parent fe8ab8a530
commit 27c90b881d
No known key found for this signature in database
GPG key ID: CFA9CCFE5363D0C6

View file

@ -692,6 +692,7 @@ impl OpenOptions {
} }
} }
impl File { impl File {
pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> { pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
let path = cstr(path)?; let path = cstr(path)?;
@ -962,6 +963,12 @@ pub fn rename(old: &Path, new: &Path) -> io::Result<()> {
Ok(()) Ok(())
} }
pub fn get_openopetions_as_cint(from: OpenOptions) -> io::Result<libc::c_int> {
let access_mode = from.get_access_mode()?;
let creation_mode = from.get_creation_mode()?;
Ok(creation_mode | access_mode)
}
pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> { pub fn set_perm(p: &Path, perm: FilePermissions) -> io::Result<()> {
let p = cstr(p)?; let p = cstr(p)?;
cvt_r(|| unsafe { libc::chmod(p.as_ptr(), perm.mode) })?; cvt_r(|| unsafe { libc::chmod(p.as_ptr(), perm.mode) })?;