Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
095d8212
Commit
095d8212
authored
Sep 25, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use xopen in readlink
parent
e23f23a8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
2 deletions
+23
-2
files.rs
native/src/base/files.rs
+23
-2
No files found.
native/src/base/files.rs
View file @
095d8212
use
std
::
ffi
::
CStr
;
use
std
::
os
::
unix
::
io
::{
AsRawFd
,
FromRawFd
,
OwnedFd
,
RawFd
};
use
libc
::{
c_char
,
mode_t
,
EEXIST
,
ENOENT
,
O_CLOEXEC
,
O_PATH
};
use
libc
::{
c_char
,
c_uint
,
mode_t
,
EEXIST
,
ENOENT
,
O_CLOEXEC
,
O_PATH
};
use
crate
::{
bfmt_cstr
,
errno
,
xopen
};
...
...
@@ -27,6 +27,17 @@ pub mod unsafe_impl {
}
}
pub
fn
__open_fd_impl
(
path
:
&
CStr
,
flags
:
i32
,
mode
:
mode_t
)
->
Option
<
OwnedFd
>
{
unsafe
{
let
fd
=
libc
::
open
(
path
.as_ptr
(),
flags
,
mode
as
c_uint
);
if
fd
>=
0
{
Some
(
OwnedFd
::
from_raw_fd
(
fd
))
}
else
{
None
}
}
}
pub
fn
__xopen_fd_impl
(
path
:
&
CStr
,
flags
:
i32
,
mode
:
mode_t
)
->
Option
<
OwnedFd
>
{
let
fd
=
xopen
(
path
.as_ptr
(),
flags
,
mode
);
if
fd
>=
0
{
...
...
@@ -36,6 +47,16 @@ pub fn __xopen_fd_impl(path: &CStr, flags: i32, mode: mode_t) -> Option<OwnedFd>
}
}
#[macro_export]
macro_rules!
open_fd
{
(
$path:expr
,
$flags:expr
)
=>
{
crate
::
__open_fd_impl
(
$path
,
$flags
,
0
)
};
(
$path:expr
,
$flags:expr
,
$mode:expr
)
=>
{
crate
::
__open_fd_impl
(
$path
,
$flags
,
$mode
)
};
}
#[macro_export]
macro_rules!
xopen_fd
{
(
$path:expr
,
$flags:expr
)
=>
{
...
...
@@ -58,7 +79,7 @@ pub fn fd_path(fd: RawFd, buf: &mut [u8]) -> isize {
// Inspired by https://android.googlesource.com/platform/bionic/+/master/libc/bionic/realpath.cpp
pub
fn
realpath
(
path
:
&
CStr
,
buf
:
&
mut
[
u8
])
->
isize
{
if
let
Some
(
fd
)
=
x
open_fd!
(
path
,
O_PATH
|
O_CLOEXEC
)
{
if
let
Some
(
fd
)
=
open_fd!
(
path
,
O_PATH
|
O_CLOEXEC
)
{
let
mut
st1
:
libc
::
stat
;
let
mut
st2
:
libc
::
stat
;
unsafe
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment