Merge pull request #8 from NikVolf/fix-signatures

Match signatures of SecurityAttributes funcs on unix
This commit is contained in:
Emīls Piņķis 2018-08-27 15:54:06 +01:00 committed by GitHub
commit fe3de17621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -1,9 +1,16 @@
use std::io;
/// A NOOP struct for bringing the API between Windows and Unix up to parity. To set permissions
/// properly on Unix, you can just use `std::os::unix::fs::PermissionsExt`.
pub struct SecurityAttributes;
impl SecurityAttributes {
/// New default security attributes.
pub fn empty() -> Self { SecurityAttributes }
pub fn allow_everyone_connect() -> Self { SecurityAttributes }
pub fn allow_everyone_create() -> Self { SecurityAttributes }
/// New security attributes that allow everyone to connect.
pub fn allow_everyone_connect() -> io::Result<Self> { Ok(SecurityAttributes) }
/// New security attributes that allow everyone to create.
pub fn allow_everyone_create() -> io::Result<Self> { Ok(SecurityAttributes) }
}

View File

@ -11,26 +11,31 @@ use std::io;
use std::mem;
use std::marker;
/// Security attributes.
pub struct SecurityAttributes {
attributes: Option<InnerAttributes>,
}
impl SecurityAttributes {
/// New default security attributes.
pub fn empty() -> SecurityAttributes {
SecurityAttributes { attributes: None }
}
/// New default security attributes that allow everyone to connect.
pub fn allow_everyone_connect() -> io::Result<SecurityAttributes> {
let attributes = Some(InnerAttributes::allow_everyone(GENERIC_READ | FILE_WRITE_DATA)?);
Ok(SecurityAttributes { attributes })
}
/// New default security attributes that allow everyone to create.
pub fn allow_everyone_create() -> io::Result<SecurityAttributes> {
let attributes = Some(InnerAttributes::allow_everyone(GENERIC_READ | GENERIC_WRITE)?);
Ok(SecurityAttributes { attributes })
}
pub unsafe fn as_ptr(&mut self) -> PSECURITY_ATTRIBUTES {
/// Return raw handle of security attributes.
pub(crate) unsafe fn as_ptr(&mut self) -> PSECURITY_ATTRIBUTES {
match self.attributes.as_mut() {
Some(attributes) => attributes.as_ptr(),
None => ptr::null_mut(),