mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-15 18:10:23 +00:00
Add new util function
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
/* file.cpp - Contains all files related utilities
|
||||
*/
|
||||
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/mman.h>
|
||||
#include <linux/fs.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/mman.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include <magisk.h>
|
||||
#include <utils.h>
|
||||
@@ -396,3 +396,14 @@ void parse_prop_file(const char *file, const function<bool (string_view, string_
|
||||
return fn(line, eql + 1);
|
||||
}, true);
|
||||
}
|
||||
|
||||
void parse_mnt(const char *file, const function<bool (mntent*)> &fn) {
|
||||
unique_ptr<FILE, decltype(&fclose)> fp(xfopen(file, "rce"), &fclose);
|
||||
if (fp) {
|
||||
mntent *mentry;
|
||||
while ((mentry = getmntent(fp.get())) != nullptr) {
|
||||
if (!fn(mentry))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,13 +3,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <pthread.h>
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <mntent.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -173,6 +174,7 @@ void parse_prop_file(const char *file, const std::function
|
||||
void *__mmap(const char *filename, size_t *size, bool rw);
|
||||
void frm_rf(int dirfd, std::initializer_list<const char *> excl = std::initializer_list<const char *>());
|
||||
void clone_dir(int src, int dest, bool overwrite = true);
|
||||
void parse_mnt(const char *file, const std::function<bool (mntent*)> &fn);
|
||||
|
||||
template <typename B>
|
||||
void mmap_ro(const char *filename, B &buf, size_t &sz) {
|
||||
|
Reference in New Issue
Block a user