mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 07:57:39 +00:00
Remove fopen usage in magiskinit
This commit is contained in:
parent
3185e5a7ca
commit
b7505c3c9c
@ -75,9 +75,14 @@ void file_readline(bool trim, FILE *fp, const function<bool(string_view)> &fn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void file_readline(bool trim, const char *file, const function<bool(string_view)> &fn) {
|
void file_readline(bool trim, const char *file, const function<bool(string_view)> &fn) {
|
||||||
if (auto fp = open_file(file, "re"))
|
int fd = xopen(file, O_RDONLY | O_CLOEXEC);
|
||||||
file_readline(trim, fp.get(), fn);
|
if (fd >= 0) {
|
||||||
|
auto fp = fdopen(fd, "re");
|
||||||
|
file_readline(trim, fp, fn);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void file_readline(const char *file, const function<bool(string_view)> &fn) {
|
void file_readline(const char *file, const function<bool(string_view)> &fn) {
|
||||||
file_readline(false, file, fn);
|
file_readline(false, file, fn);
|
||||||
}
|
}
|
||||||
@ -96,8 +101,12 @@ void parse_prop_file(FILE *fp, const function<bool(string_view, string_view)> &f
|
|||||||
}
|
}
|
||||||
|
|
||||||
void parse_prop_file(const char *file, const function<bool(string_view, string_view)> &fn) {
|
void parse_prop_file(const char *file, const function<bool(string_view, string_view)> &fn) {
|
||||||
if (auto fp = open_file(file, "re"))
|
int fd = xopen(file, O_RDONLY | O_CLOEXEC);
|
||||||
parse_prop_file(fp.get(), fn);
|
if (fd >= 0) {
|
||||||
|
auto fp = fdopen(fd, "re");
|
||||||
|
parse_prop_file(fp, fn);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<mount_info> parse_mount_info(const char *pid) {
|
std::vector<mount_info> parse_mount_info(const char *pid) {
|
||||||
|
@ -103,7 +103,8 @@ sepolicy *sepolicy::from_file(const char *file) {
|
|||||||
|
|
||||||
policy_file_t pf;
|
policy_file_t pf;
|
||||||
policy_file_init(&pf);
|
policy_file_init(&pf);
|
||||||
auto fp = xopen_file(file, "re");
|
int fd = xopen(file, O_RDONLY | O_CLOEXEC);
|
||||||
|
auto fp = make_file(fdopen(fd, "re"));
|
||||||
pf.fp = fp.get();
|
pf.fp = fp.get();
|
||||||
pf.type = PF_USE_STDIO;
|
pf.type = PF_USE_STDIO;
|
||||||
|
|
||||||
@ -123,6 +124,7 @@ sepolicy *sepolicy::compile_split() {
|
|||||||
cil_db_t *db = nullptr;
|
cil_db_t *db = nullptr;
|
||||||
sepol_policydb_t *pdb = nullptr;
|
sepol_policydb_t *pdb = nullptr;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
int fd;
|
||||||
int policy_ver;
|
int policy_ver;
|
||||||
const char *cil_file;
|
const char *cil_file;
|
||||||
#if MAGISK_DEBUG
|
#if MAGISK_DEBUG
|
||||||
@ -148,13 +150,15 @@ sepolicy *sepolicy::compile_split() {
|
|||||||
cil_set_target_platform(db, SEPOL_TARGET_SELINUX);
|
cil_set_target_platform(db, SEPOL_TARGET_SELINUX);
|
||||||
cil_set_attrs_expand_generated(db, 1);
|
cil_set_attrs_expand_generated(db, 1);
|
||||||
|
|
||||||
f = xfopen(SELINUX_VERSION, "re");
|
fd = xopen(SELINUX_VERSION, O_RDONLY | O_CLOEXEC);
|
||||||
|
f = fdopen(fd, "re");
|
||||||
fscanf(f, "%d", &policy_ver);
|
fscanf(f, "%d", &policy_ver);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
cil_set_policy_version(db, policy_ver);
|
cil_set_policy_version(db, policy_ver);
|
||||||
|
|
||||||
// Get mapping version
|
// Get mapping version
|
||||||
f = xfopen(VEND_POLICY_DIR "plat_sepolicy_vers.txt", "re");
|
fd = xopen(VEND_POLICY_DIR "plat_sepolicy_vers.txt", O_RDONLY | O_CLOEXEC);
|
||||||
|
f = fdopen(fd, "re");
|
||||||
fscanf(f, "%s", plat_ver);
|
fscanf(f, "%s", plat_ver);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user