mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-12 08:32:07 +00:00
Rename cstr_buf to cstr::buf
This commit is contained in:
@@ -21,7 +21,7 @@ use crate::{FsPath, FsPathMnt, slice_from_ptr_mut};
|
||||
// Utf8CStrBufRef: reference to a fixed sized buffer
|
||||
// Utf8CStrBufArr<N>: fixed sized buffer allocated on the stack
|
||||
//
|
||||
// For easier usage, please use the helper functions in cstr_buf.
|
||||
// For easier usage, please use the helper functions in cstr::buf.
|
||||
//
|
||||
// In most cases, these are the types being used
|
||||
//
|
||||
@@ -36,7 +36,7 @@ use crate::{FsPath, FsPathMnt, slice_from_ptr_mut};
|
||||
|
||||
// Public helper functions
|
||||
|
||||
pub mod cstr_buf {
|
||||
pub mod buf {
|
||||
use super::{Utf8CStrBufArr, Utf8CStrBufRef, Utf8CString};
|
||||
|
||||
#[inline(always)]
|
||||
@@ -118,7 +118,7 @@ impl<'a> From<&'a mut dyn Utf8CStrBuf> for Utf8CStrBuffer<'a, 0> {
|
||||
|
||||
impl Default for Utf8CStrBuffer<'static, 4096> {
|
||||
fn default() -> Self {
|
||||
Utf8CStrBuffer::Array(cstr_buf::default())
|
||||
Utf8CStrBuffer::Array(buf::default())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@ use libc::{c_char, mode_t};
|
||||
use crate::files::map_file_at;
|
||||
pub(crate) use crate::xwrap::*;
|
||||
use crate::{
|
||||
CxxResultExt, Directory, FsPath, OsResultStatic, Utf8CStr, clone_attr, cstr, cstr_buf,
|
||||
fclone_attr, fd_path, map_fd, map_file, slice_from_ptr,
|
||||
CxxResultExt, Directory, FsPath, OsResultStatic, Utf8CStr, clone_attr, cstr, fclone_attr,
|
||||
fd_path, map_fd, map_file, slice_from_ptr,
|
||||
};
|
||||
|
||||
pub(crate) fn fd_path_for_cxx(fd: RawFd, buf: &mut [u8]) -> isize {
|
||||
let mut buf = cstr_buf::wrap(buf);
|
||||
let mut buf = cstr::buf::wrap(buf);
|
||||
fd_path(fd, &mut buf)
|
||||
.log_cxx()
|
||||
.map_or(-1_isize, |_| buf.len() as isize)
|
||||
@@ -24,7 +24,7 @@ unsafe extern "C" fn canonical_path(path: *const c_char, buf: *mut u8, bufsz: us
|
||||
unsafe {
|
||||
match Utf8CStr::from_ptr(path) {
|
||||
Ok(path) => {
|
||||
let mut buf = cstr_buf::wrap_ptr(buf, bufsz);
|
||||
let mut buf = cstr::buf::wrap_ptr(buf, bufsz);
|
||||
path.realpath(&mut buf)
|
||||
.log_cxx()
|
||||
.map_or(-1_isize, |_| buf.len() as isize)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::cxx_extern::readlinkat;
|
||||
use crate::{
|
||||
FileAttr, FsPath, FsPathBuilder, LibcReturn, OsError, OsResult, OsResultStatic, Utf8CStr,
|
||||
Utf8CStrBuf, cstr_buf, errno, fd_path, fd_set_attr,
|
||||
Utf8CStrBuf, cstr, errno, fd_path, fd_set_attr,
|
||||
};
|
||||
use libc::{EEXIST, O_CLOEXEC, O_CREAT, O_RDONLY, O_TRUNC, O_WRONLY, dirent, mode_t};
|
||||
use std::fs::File;
|
||||
@@ -247,13 +247,13 @@ impl Directory {
|
||||
}
|
||||
|
||||
pub fn get_attr_at<'a>(&self, name: &'a Utf8CStr) -> OsResult<'a, FileAttr> {
|
||||
let mut path = cstr_buf::default();
|
||||
let mut path = cstr::buf::default();
|
||||
self.path_at(name, &mut path)?;
|
||||
path.get_attr().map_err(|e| e.set_args(Some(name), None))
|
||||
}
|
||||
|
||||
pub fn set_attr_at<'a>(&self, name: &'a Utf8CStr, attr: &FileAttr) -> OsResult<'a, ()> {
|
||||
let mut path = cstr_buf::default();
|
||||
let mut path = cstr::buf::default();
|
||||
self.path_at(name, &mut path)?;
|
||||
path.set_attr(attr)
|
||||
.map_err(|e| e.set_args(Some(name), None))
|
||||
@@ -264,14 +264,14 @@ impl Directory {
|
||||
name: &'a Utf8CStr,
|
||||
con: &mut dyn Utf8CStrBuf,
|
||||
) -> OsResult<'a, ()> {
|
||||
let mut path = cstr_buf::default();
|
||||
let mut path = cstr::buf::default();
|
||||
self.path_at(name, &mut path)?;
|
||||
path.get_secontext(con)
|
||||
.map_err(|e| e.set_args(Some(name), None))
|
||||
}
|
||||
|
||||
pub fn set_secontext_at<'a>(&self, name: &'a Utf8CStr, con: &'a Utf8CStr) -> OsResult<'a, ()> {
|
||||
let mut path = cstr_buf::default();
|
||||
let mut path = cstr::buf::default();
|
||||
self.path_at(name, &mut path)?;
|
||||
path.set_secontext(con)
|
||||
.map_err(|e| e.set_args(Some(name), Some(con)))
|
||||
@@ -344,7 +344,7 @@ impl Directory {
|
||||
std::io::copy(&mut src, &mut dest)?;
|
||||
fd_set_attr(dest.as_raw_fd(), &attr)?;
|
||||
} else if e.is_symlink() {
|
||||
let mut target = cstr_buf::default();
|
||||
let mut target = cstr::buf::default();
|
||||
e.read_link(&mut target)?;
|
||||
unsafe {
|
||||
libc::symlinkat(target.as_ptr(), dir.as_raw_fd(), e.d_name.as_ptr())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
Directory, FsPathFollow, LibcReturn, OsError, OsResult, OsResultStatic, Utf8CStr, Utf8CStrBuf,
|
||||
cstr_buf, errno, error,
|
||||
cstr, errno, error,
|
||||
};
|
||||
use bytemuck::{Pod, bytes_of, bytes_of_mut};
|
||||
use libc::{
|
||||
@@ -139,7 +139,7 @@ macro_rules! open_fd {
|
||||
}
|
||||
|
||||
pub fn fd_path(fd: RawFd, buf: &mut dyn Utf8CStrBuf) -> OsResult<'static, ()> {
|
||||
let path = cstr_buf::default()
|
||||
let path = cstr::buf::default()
|
||||
.join_path("/proc/self/fd")
|
||||
.join_path_fmt(fd);
|
||||
path.read_link(buf).map_err(|e| e.set_args(None, None))
|
||||
@@ -270,7 +270,7 @@ pub trait FsPath: Deref<Target = Utf8CStr> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut path = cstr_buf::default();
|
||||
let mut path = cstr::buf::default();
|
||||
let mut components = self.split('/').filter(|s| !s.is_empty());
|
||||
loop {
|
||||
let Some(s) = components.next() else {
|
||||
@@ -396,7 +396,7 @@ pub trait FsPath: Deref<Target = Utf8CStr> {
|
||||
let mut dest = path.create(O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0o777)?;
|
||||
std::io::copy(&mut src, &mut dest)?;
|
||||
} else if attr.is_symlink() {
|
||||
let mut buf = cstr_buf::default();
|
||||
let mut buf = cstr::buf::default();
|
||||
self.read_link(&mut buf)?;
|
||||
unsafe {
|
||||
libc::symlink(buf.as_ptr(), path.as_ptr()).check_os_err(
|
||||
|
||||
@@ -6,7 +6,9 @@ pub use const_format;
|
||||
pub use libc;
|
||||
use num_traits::FromPrimitive;
|
||||
|
||||
pub use cstr::*;
|
||||
pub use cstr::{
|
||||
FsPathFollow, StrErr, Utf8CStr, Utf8CStrBuf, Utf8CStrBufArr, Utf8CStrBufRef, Utf8CString,
|
||||
};
|
||||
use cxx_extern::*;
|
||||
pub use dir::*;
|
||||
pub use ffi::fork_dont_care;
|
||||
@@ -16,7 +18,7 @@ pub use misc::*;
|
||||
pub use mount::*;
|
||||
pub use result::*;
|
||||
|
||||
mod cstr;
|
||||
pub mod cstr;
|
||||
mod cxx_extern;
|
||||
mod dir;
|
||||
mod files;
|
||||
|
||||
@@ -7,7 +7,7 @@ use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::FromPrimitive;
|
||||
|
||||
use crate::ffi::LogLevelCxx;
|
||||
use crate::{Utf8CStr, cstr_buf};
|
||||
use crate::{Utf8CStr, cstr};
|
||||
|
||||
// Ugly hack to avoid using enum
|
||||
#[allow(non_snake_case, non_upper_case_globals)]
|
||||
@@ -96,7 +96,7 @@ pub fn log_from_cxx(level: LogLevelCxx, msg: &Utf8CStr) {
|
||||
|
||||
pub fn log_with_formatter<F: FnOnce(Formatter) -> fmt::Result>(level: LogLevel, f: F) {
|
||||
log_with_writer(level, |write| {
|
||||
let mut buf = cstr_buf::default();
|
||||
let mut buf = cstr::buf::default();
|
||||
f(&mut buf).ok();
|
||||
write(level, &buf);
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::cxx_extern::readlinkat;
|
||||
use crate::{
|
||||
BorrowedDirectory, CxxResultExt, FsPath, LibcReturn, Utf8CStr, cstr_buf, slice_from_ptr,
|
||||
BorrowedDirectory, CxxResultExt, FsPath, LibcReturn, Utf8CStr, cstr, slice_from_ptr,
|
||||
slice_from_ptr_mut,
|
||||
};
|
||||
use libc::{
|
||||
@@ -30,7 +30,7 @@ unsafe extern "C" fn xrealpath(path: *const c_char, buf: *mut u8, bufsz: usize)
|
||||
unsafe {
|
||||
match Utf8CStr::from_ptr(path) {
|
||||
Ok(path) => {
|
||||
let mut buf = cstr_buf::wrap_ptr(buf, bufsz);
|
||||
let mut buf = cstr::buf::wrap_ptr(buf, bufsz);
|
||||
path.realpath(&mut buf)
|
||||
.log_cxx()
|
||||
.map_or(-1, |_| buf.len() as isize)
|
||||
@@ -45,7 +45,7 @@ unsafe extern "C" fn xreadlink(path: *const c_char, buf: *mut u8, bufsz: usize)
|
||||
unsafe {
|
||||
match Utf8CStr::from_ptr(path) {
|
||||
Ok(path) => {
|
||||
let mut buf = cstr_buf::wrap_ptr(buf, bufsz);
|
||||
let mut buf = cstr::buf::wrap_ptr(buf, bufsz);
|
||||
path.read_link(&mut buf)
|
||||
.log_cxx()
|
||||
.map_or(-1, |_| buf.len() as isize)
|
||||
|
||||
Reference in New Issue
Block a user