mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-29 22:14:27 +02:00
Cleanup cstr implementation
This commit is contained in:
parent
c8a16b0e0c
commit
c34c7838bb
@ -125,9 +125,7 @@ impl Default for Utf8CStrBuffer<'static, 4096> {
|
|||||||
|
|
||||||
// Trait definitions
|
// Trait definitions
|
||||||
|
|
||||||
pub trait Utf8CStrBuf:
|
pub trait Utf8CStrBuf: Write + AsRef<Utf8CStr> + Deref<Target = Utf8CStr> {
|
||||||
Write + AsRef<Utf8CStr> + AsMut<Utf8CStr> + Deref<Target = Utf8CStr> + DerefMut
|
|
||||||
{
|
|
||||||
// The length of the string without the terminating null character.
|
// The length of the string without the terminating null character.
|
||||||
// assert_true(len <= capacity - 1)
|
// assert_true(len <= capacity - 1)
|
||||||
fn len(&self) -> usize;
|
fn len(&self) -> usize;
|
||||||
@ -143,6 +141,7 @@ pub trait Utf8CStrBuf:
|
|||||||
// is capacity - 1, because the last byte is reserved for the terminating null character.
|
// is capacity - 1, because the last byte is reserved for the terminating null character.
|
||||||
fn capacity(&self) -> usize;
|
fn capacity(&self) -> usize;
|
||||||
fn clear(&mut self);
|
fn clear(&mut self);
|
||||||
|
fn as_mut_ptr(&mut self) -> *mut c_char;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
@ -150,52 +149,8 @@ pub trait Utf8CStrBuf:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait Utf8CStrBufWithSlice: Utf8CStrBuf {
|
|
||||||
fn buf(&self) -> &[u8];
|
|
||||||
unsafe fn mut_buf(&mut self) -> &mut [u8];
|
|
||||||
}
|
|
||||||
|
|
||||||
trait AsUtf8CStr {
|
trait AsUtf8CStr {
|
||||||
fn as_utf8_cstr(&self) -> &Utf8CStr;
|
fn as_utf8_cstr(&self) -> &Utf8CStr;
|
||||||
fn as_utf8_cstr_mut(&mut self) -> &mut Utf8CStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Utf8CStrBufWithSlice> AsUtf8CStr for T {
|
|
||||||
#[inline(always)]
|
|
||||||
fn as_utf8_cstr(&self) -> &Utf8CStr {
|
|
||||||
// SAFETY: the internal buffer is always UTF-8 checked
|
|
||||||
// SAFETY: self.used is guaranteed to always <= SIZE - 1
|
|
||||||
unsafe { Utf8CStr::from_bytes_unchecked(self.buf().get_unchecked(..(self.len() + 1))) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn as_utf8_cstr_mut(&mut self) -> &mut Utf8CStr {
|
|
||||||
// SAFETY: the internal buffer is always UTF-8 checked
|
|
||||||
// SAFETY: self.used is guaranteed to always <= SIZE - 1
|
|
||||||
unsafe {
|
|
||||||
let len = self.len() + 1;
|
|
||||||
Utf8CStr::from_bytes_unchecked_mut(self.mut_buf().get_unchecked_mut(..len))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implementation for Utf8CString
|
|
||||||
|
|
||||||
fn utf8_cstr_append(buf: &mut dyn Utf8CStrBufWithSlice, s: &[u8]) -> usize {
|
|
||||||
let mut used = buf.len();
|
|
||||||
if used >= buf.capacity() - 1 {
|
|
||||||
// Truncate
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
let dest = unsafe { &mut buf.mut_buf()[used..] };
|
|
||||||
let len = min(s.len(), dest.len() - 1);
|
|
||||||
if len > 0 {
|
|
||||||
dest[..len].copy_from_slice(&s[..len]);
|
|
||||||
}
|
|
||||||
dest[len] = b'\0';
|
|
||||||
used += len;
|
|
||||||
unsafe { buf.set_len(used) };
|
|
||||||
len
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait StringExt {
|
pub trait StringExt {
|
||||||
@ -257,17 +212,6 @@ impl AsUtf8CStr for Utf8CString {
|
|||||||
// SAFETY: the internal string is always null terminated
|
// SAFETY: the internal string is always null terminated
|
||||||
unsafe { mem::transmute(slice::from_raw_parts(self.0.as_ptr(), self.0.len() + 1)) }
|
unsafe { mem::transmute(slice::from_raw_parts(self.0.as_ptr(), self.0.len() + 1)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn as_utf8_cstr_mut(&mut self) -> &mut Utf8CStr {
|
|
||||||
// SAFETY: the internal string is always null terminated
|
|
||||||
unsafe {
|
|
||||||
mem::transmute(slice::from_raw_parts_mut(
|
|
||||||
self.0.as_mut_ptr(),
|
|
||||||
self.0.len() + 1,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Utf8CStrBuf for Utf8CString {
|
impl Utf8CStrBuf for Utf8CString {
|
||||||
@ -296,6 +240,10 @@ impl Utf8CStrBuf for Utf8CString {
|
|||||||
self.0.clear();
|
self.0.clear();
|
||||||
self.0.nul_terminate();
|
self.0.nul_terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn as_mut_ptr(&mut self) -> *mut c_char {
|
||||||
|
self.0.as_mut_ptr().cast()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for Utf8CString {
|
impl From<String> for Utf8CString {
|
||||||
@ -330,18 +278,6 @@ impl<'a> From<&'a mut [u8]> for Utf8CStrBufRef<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Utf8CStrBufWithSlice for Utf8CStrBufRef<'_> {
|
|
||||||
#[inline(always)]
|
|
||||||
fn buf(&self) -> &[u8] {
|
|
||||||
self.buf
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
unsafe fn mut_buf(&mut self) -> &mut [u8] {
|
|
||||||
self.buf
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// UTF-8 validated + null terminated buffer on the stack
|
// UTF-8 validated + null terminated buffer on the stack
|
||||||
pub struct Utf8CStrBufArr<const N: usize> {
|
pub struct Utf8CStrBufArr<const N: usize> {
|
||||||
used: usize,
|
used: usize,
|
||||||
@ -357,18 +293,6 @@ impl<const N: usize> Utf8CStrBufArr<N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> Utf8CStrBufWithSlice for Utf8CStrBufArr<N> {
|
|
||||||
#[inline(always)]
|
|
||||||
fn buf(&self) -> &[u8] {
|
|
||||||
&self.buf
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
unsafe fn mut_buf(&mut self) -> &mut [u8] {
|
|
||||||
&mut self.buf
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Utf8CStrBufArr<4096> {
|
impl Default for Utf8CStrBufArr<4096> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Utf8CStrBufArr::<4096>::new()
|
Utf8CStrBufArr::<4096>::new()
|
||||||
@ -400,7 +324,7 @@ impl Utf8CStr {
|
|||||||
Self::from_cstr(CStr::from_bytes_with_nul(buf)?)
|
Self::from_cstr(CStr::from_bytes_with_nul(buf)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_string(s: &mut String) -> &mut Utf8CStr {
|
pub fn from_string(s: &mut String) -> &Utf8CStr {
|
||||||
let buf = s.nul_terminate();
|
let buf = s.nul_terminate();
|
||||||
// SAFETY: the null byte is explicitly added to the buffer
|
// SAFETY: the null byte is explicitly added to the buffer
|
||||||
unsafe { mem::transmute(buf) }
|
unsafe { mem::transmute(buf) }
|
||||||
@ -411,11 +335,6 @@ impl Utf8CStr {
|
|||||||
unsafe { mem::transmute(buf) }
|
unsafe { mem::transmute(buf) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
unsafe fn from_bytes_unchecked_mut(buf: &mut [u8]) -> &mut Utf8CStr {
|
|
||||||
unsafe { mem::transmute(buf) }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> Result<&'a Utf8CStr, StrErr> {
|
pub unsafe fn from_ptr<'a>(ptr: *const c_char) -> Result<&'a Utf8CStr, StrErr> {
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
return Err(StrErr::NullPointerError);
|
return Err(StrErr::NullPointerError);
|
||||||
@ -457,13 +376,6 @@ impl Utf8CStr {
|
|||||||
// SAFETY: The length of the slice is at least 1 due to null termination check
|
// SAFETY: The length of the slice is at least 1 due to null termination check
|
||||||
unsafe { str::from_utf8_unchecked(self.0.get_unchecked(..self.0.len() - 1)) }
|
unsafe { str::from_utf8_unchecked(self.0.get_unchecked(..self.0.len() - 1)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn as_str_mut(&mut self) -> &mut str {
|
|
||||||
// SAFETY: Already UTF-8 validated during construction
|
|
||||||
// SAFETY: The length of the slice is at least 1 due to null termination check
|
|
||||||
unsafe { str::from_utf8_unchecked_mut(self.0.get_unchecked_mut(..self.0.len() - 1)) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for Utf8CStr {
|
impl Deref for Utf8CStr {
|
||||||
@ -475,13 +387,6 @@ impl Deref for Utf8CStr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for Utf8CStr {
|
|
||||||
#[inline(always)]
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
||||||
self.as_str_mut()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToOwned for Utf8CStr {
|
impl ToOwned for Utf8CStr {
|
||||||
type Owned = Utf8CString;
|
type Owned = Utf8CString;
|
||||||
|
|
||||||
@ -524,47 +429,28 @@ impl FsPath {
|
|||||||
unsafe { mem::transmute(value) }
|
unsafe { mem::transmute(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
pub fn follow_link(&self) -> &FsPathFollow {
|
||||||
pub fn from_mut<T: AsMut<Utf8CStr> + ?Sized>(value: &mut T) -> &mut FsPath {
|
unsafe { mem::transmute(self) }
|
||||||
unsafe { mem::transmute(value.as_mut()) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Deref for FsPath {
|
impl AsUtf8CStr for FsPath {
|
||||||
type Target = Utf8CStr;
|
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn deref(&self) -> &Utf8CStr {
|
fn as_utf8_cstr(&self) -> &Utf8CStr {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for FsPath {
|
|
||||||
#[inline(always)]
|
|
||||||
fn deref_mut(&mut self) -> &mut Utf8CStr {
|
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct FsPathFollow(Utf8CStr);
|
pub struct FsPathFollow(Utf8CStr);
|
||||||
|
|
||||||
impl Deref for FsPathFollow {
|
impl AsUtf8CStr for FsPathFollow {
|
||||||
type Target = Utf8CStr;
|
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn deref(&self) -> &Utf8CStr {
|
fn as_utf8_cstr(&self) -> &Utf8CStr {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for FsPathFollow {
|
|
||||||
#[inline(always)]
|
|
||||||
fn deref_mut(&mut self) -> &mut Utf8CStr {
|
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct FsPathBuf<'a, const N: usize>(pub Utf8CStrBuffer<'a, N>);
|
pub struct FsPathBuf<'a, const N: usize>(pub Utf8CStrBuffer<'a, N>);
|
||||||
|
|
||||||
impl From<Utf8CString> for FsPathBuf<'static, 0> {
|
impl From<Utf8CString> for FsPathBuf<'static, 0> {
|
||||||
@ -624,15 +510,30 @@ impl<const N: usize> Deref for FsPathBuf<'_, N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> DerefMut for FsPathBuf<'_, N> {
|
// impl<T: AsUtf8CStr> Deref<Target = Utf8CStr> for T { ... }
|
||||||
fn deref_mut(&mut self) -> &mut FsPath {
|
macro_rules! impl_cstr_deref {
|
||||||
FsPath::from_mut(self.0.deref_mut())
|
($( ($t:ty, $($g:tt)*) )*) => {$(
|
||||||
}
|
impl<$($g)*> Deref for $t {
|
||||||
|
type Target = Utf8CStr;
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn deref(&self) -> &Utf8CStr {
|
||||||
|
self.as_utf8_cstr()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Boilerplate trait implementations
|
impl_cstr_deref!(
|
||||||
|
(FsPath,)
|
||||||
|
(FsPathFollow,)
|
||||||
|
(Utf8CStrBufRef<'_>,)
|
||||||
|
(Utf8CStrBufArr<N>, const N: usize)
|
||||||
|
(Utf8CString,)
|
||||||
|
);
|
||||||
|
|
||||||
macro_rules! impl_str {
|
// impl<T: Deref<Target = Utf8CStr>> BoilerPlate for T { ... }
|
||||||
|
macro_rules! impl_cstr_misc {
|
||||||
($( ($t:ty, $($g:tt)*) )*) => {$(
|
($( ($t:ty, $($g:tt)*) )*) => {$(
|
||||||
impl<$($g)*> AsRef<Utf8CStr> for $t {
|
impl<$($g)*> AsRef<Utf8CStr> for $t {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -709,7 +610,7 @@ macro_rules! impl_str {
|
|||||||
)*}
|
)*}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_str!(
|
impl_cstr_misc!(
|
||||||
(Utf8CStr,)
|
(Utf8CStr,)
|
||||||
(FsPath,)
|
(FsPath,)
|
||||||
(FsPathFollow,)
|
(FsPathFollow,)
|
||||||
@ -719,46 +620,31 @@ impl_str!(
|
|||||||
(Utf8CString,)
|
(Utf8CString,)
|
||||||
);
|
);
|
||||||
|
|
||||||
macro_rules! impl_str_buf {
|
fn copy_cstr_truncate(dest: &mut [u8], src: &[u8]) -> usize {
|
||||||
($( ($t:ty, $($g:tt)*) )*) => {$(
|
if dest.len() <= 1 {
|
||||||
impl<$($g)*> Write for $t {
|
// Truncate
|
||||||
#[inline(always)]
|
return 0;
|
||||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
}
|
||||||
self.push_str(s);
|
let len = min(src.len(), dest.len() - 1);
|
||||||
Ok(())
|
if len > 0 {
|
||||||
}
|
dest[..len].copy_from_slice(&src[..len]);
|
||||||
}
|
}
|
||||||
impl<$($g)*> Deref for $t {
|
dest[len] = b'\0';
|
||||||
type Target = Utf8CStr;
|
len
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn deref(&self) -> &Utf8CStr {
|
|
||||||
self.as_utf8_cstr()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<$($g)*> DerefMut for $t {
|
|
||||||
#[inline(always)]
|
|
||||||
fn deref_mut(&mut self) -> &mut Utf8CStr {
|
|
||||||
self.as_utf8_cstr_mut()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<$($g)*> AsMut<Utf8CStr> for $t {
|
|
||||||
#[inline(always)]
|
|
||||||
fn as_mut(&mut self) -> &mut Utf8CStr {
|
|
||||||
self.as_utf8_cstr_mut()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)*}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_str_buf!(
|
// impl<T> AsUtf8CStr for T { ... }
|
||||||
(Utf8CStrBufRef<'_>,)
|
// impl<T> Utf8CStrBuf for T { ... }
|
||||||
(Utf8CStrBufArr<N>, const N: usize)
|
macro_rules! impl_cstr_buf {
|
||||||
(Utf8CString,)
|
|
||||||
);
|
|
||||||
|
|
||||||
macro_rules! impl_str_buf_with_slice {
|
|
||||||
($( ($t:ty, $($g:tt)*) )*) => {$(
|
($( ($t:ty, $($g:tt)*) )*) => {$(
|
||||||
|
impl<$($g)*> AsUtf8CStr for $t {
|
||||||
|
#[inline(always)]
|
||||||
|
fn as_utf8_cstr(&self) -> &Utf8CStr {
|
||||||
|
// SAFETY: the internal buffer is always UTF-8 checked
|
||||||
|
// SAFETY: self.used is guaranteed to always <= SIZE - 1
|
||||||
|
unsafe { Utf8CStr::from_bytes_unchecked(self.buf.get_unchecked(..(self.used + 1))) }
|
||||||
|
}
|
||||||
|
}
|
||||||
impl<$($g)*> Utf8CStrBuf for $t {
|
impl<$($g)*> Utf8CStrBuf for $t {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn len(&self) -> usize {
|
fn len(&self) -> usize {
|
||||||
@ -770,7 +656,11 @@ macro_rules! impl_str_buf_with_slice {
|
|||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn push_str(&mut self, s: &str) -> usize {
|
fn push_str(&mut self, s: &str) -> usize {
|
||||||
utf8_cstr_append(self, s.as_bytes())
|
// SAFETY: self.used is guaranteed to always <= SIZE - 1
|
||||||
|
let dest = unsafe { self.buf.get_unchecked_mut(self.used..) };
|
||||||
|
let len = copy_cstr_truncate(dest, s.as_bytes());
|
||||||
|
self.used += len;
|
||||||
|
len
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn capacity(&self) -> usize {
|
fn capacity(&self) -> usize {
|
||||||
@ -781,15 +671,38 @@ macro_rules! impl_str_buf_with_slice {
|
|||||||
self.buf[0] = b'\0';
|
self.buf[0] = b'\0';
|
||||||
self.used = 0;
|
self.used = 0;
|
||||||
}
|
}
|
||||||
|
#[inline(always)]
|
||||||
|
fn as_mut_ptr(&mut self) -> *mut c_char {
|
||||||
|
self.buf.as_mut_ptr().cast()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)*}
|
)*}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_str_buf_with_slice!(
|
impl_cstr_buf!(
|
||||||
(Utf8CStrBufRef<'_>,)
|
(Utf8CStrBufRef<'_>,)
|
||||||
(Utf8CStrBufArr<N>, const N: usize)
|
(Utf8CStrBufArr<N>, const N: usize)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// impl<T: Utf8CStrBuf> Write for T { ... }
|
||||||
|
macro_rules! impl_cstr_buf_write {
|
||||||
|
($( ($t:ty, $($g:tt)*) )*) => {$(
|
||||||
|
impl<$($g)*> Write for $t {
|
||||||
|
#[inline(always)]
|
||||||
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||||
|
self.push_str(s);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)*}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_cstr_buf_write!(
|
||||||
|
(Utf8CStrBufRef<'_>,)
|
||||||
|
(Utf8CStrBufArr<N>, const N: usize)
|
||||||
|
(Utf8CString,)
|
||||||
|
);
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! cstr {
|
macro_rules! cstr {
|
||||||
($str:expr) => {{
|
($str:expr) => {{
|
||||||
|
@ -194,10 +194,6 @@ impl FileAttr {
|
|||||||
const XATTR_NAME_SELINUX: &CStr = c"security.selinux";
|
const XATTR_NAME_SELINUX: &CStr = c"security.selinux";
|
||||||
|
|
||||||
impl FsPath {
|
impl FsPath {
|
||||||
pub fn follow_link(&self) -> &FsPathFollow {
|
|
||||||
unsafe { mem::transmute(self) }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn open(&self, flags: i32) -> OsResult<File> {
|
pub fn open(&self, flags: i32) -> OsResult<File> {
|
||||||
Ok(File::from(open_fd!(self, flags)?))
|
Ok(File::from(open_fd!(self, flags)?))
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ fn file_set_prop(name: &Utf8CStr, value: Option<&Utf8CStr>) -> LoggedResult<()>
|
|||||||
.join("prop.XXXXXX");
|
.join("prop.XXXXXX");
|
||||||
{
|
{
|
||||||
let mut f = unsafe {
|
let mut f = unsafe {
|
||||||
mkstemp(tmp.as_mut_ptr())
|
mkstemp(tmp.0.as_mut_ptr())
|
||||||
.as_os_result("mkstemp", None, None)
|
.as_os_result("mkstemp", None, None)
|
||||||
.map(|fd| File::from_raw_fd(fd))?
|
.map(|fd| File::from_raw_fd(fd))?
|
||||||
};
|
};
|
||||||
@ -114,7 +114,7 @@ fn proto_write_props(props: &PersistentProperties) -> LoggedResult<()> {
|
|||||||
let mut tmp = FsPathBuf::default().join(concatcp!(PERSIST_PROP, ".XXXXXX"));
|
let mut tmp = FsPathBuf::default().join(concatcp!(PERSIST_PROP, ".XXXXXX"));
|
||||||
{
|
{
|
||||||
let f = unsafe {
|
let f = unsafe {
|
||||||
mkstemp(tmp.as_mut_ptr())
|
mkstemp(tmp.0.as_mut_ptr())
|
||||||
.as_os_result("mkstemp", None, None)
|
.as_os_result("mkstemp", None, None)
|
||||||
.map(|fd| File::from_raw_fd(fd))?
|
.map(|fd| File::from_raw_fd(fd))?
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user