mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-15 17:10:17 +00:00
Add missing functions in bionic
This commit is contained in:
@@ -20,14 +20,13 @@
|
||||
#include <sys/mount.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <logging.h>
|
||||
#include <utils.h>
|
||||
|
||||
FILE *xfopen(const char *pathname, const char *mode) {
|
||||
FILE *fp = fopen(pathname, mode);
|
||||
if (fp == NULL) {
|
||||
if (fp == nullptr) {
|
||||
PLOGE("fopen: %s", pathname);
|
||||
}
|
||||
return fp;
|
||||
@@ -35,7 +34,7 @@ FILE *xfopen(const char *pathname, const char *mode) {
|
||||
|
||||
FILE *xfdopen(int fd, const char *mode) {
|
||||
FILE *fp = fdopen(fd, mode);
|
||||
if (fp == NULL) {
|
||||
if (fp == nullptr) {
|
||||
PLOGE("fopen");
|
||||
}
|
||||
return fp;
|
||||
@@ -100,7 +99,7 @@ int xpipe2(int pipefd[2], int flags) {
|
||||
}
|
||||
|
||||
int xsetns(int fd, int nstype) {
|
||||
int ret = (int) syscall(__NR_setns, fd, nstype);
|
||||
int ret = setns(fd, nstype);
|
||||
if (ret == -1) {
|
||||
PLOGE("setns");
|
||||
}
|
||||
@@ -108,7 +107,7 @@ int xsetns(int fd, int nstype) {
|
||||
}
|
||||
|
||||
int xunshare(int flags) {
|
||||
int ret = (int) syscall(__NR_unshare, flags);
|
||||
int ret = unshare(flags);
|
||||
if (ret == -1) {
|
||||
PLOGE("unshare");
|
||||
}
|
||||
@@ -117,7 +116,7 @@ int xunshare(int flags) {
|
||||
|
||||
DIR *xopendir(const char *name) {
|
||||
DIR *d = opendir(name);
|
||||
if (d == NULL) {
|
||||
if (d == nullptr) {
|
||||
PLOGE("opendir: %s", name);
|
||||
}
|
||||
return d;
|
||||
@@ -125,7 +124,7 @@ DIR *xopendir(const char *name) {
|
||||
|
||||
DIR *xfdopendir(int fd) {
|
||||
DIR *d = fdopendir(fd);
|
||||
if (d == NULL) {
|
||||
if (d == nullptr) {
|
||||
PLOGE("fdopendir");
|
||||
}
|
||||
return d;
|
||||
@@ -134,7 +133,7 @@ DIR *xfdopendir(int fd) {
|
||||
struct dirent *xreaddir(DIR *dirp) {
|
||||
errno = 0;
|
||||
struct dirent *e = readdir(dirp);
|
||||
if (errno && e == NULL) {
|
||||
if (errno && e == nullptr) {
|
||||
PLOGE("readdir");
|
||||
}
|
||||
return e;
|
||||
@@ -188,7 +187,7 @@ static int accept4_compat(int sockfd, struct sockaddr *addr, socklen_t *addrlen,
|
||||
}
|
||||
|
||||
int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
|
||||
int fd = (int) syscall(__NR_accept4, sockfd, addr, addrlen, flags);
|
||||
int fd = accept4(sockfd, addr, addrlen, flags);
|
||||
if (fd == -1) {
|
||||
if (errno == ENOSYS)
|
||||
return accept4_compat(sockfd, addr, addrlen, flags);
|
||||
@@ -199,7 +198,7 @@ int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
|
||||
|
||||
void *xmalloc(size_t size) {
|
||||
void *p = malloc(size);
|
||||
if (p == NULL) {
|
||||
if (p == nullptr) {
|
||||
PLOGE("malloc");
|
||||
}
|
||||
return p;
|
||||
@@ -207,7 +206,7 @@ void *xmalloc(size_t size) {
|
||||
|
||||
void *xcalloc(size_t nmemb, size_t size) {
|
||||
void *p = calloc(nmemb, size);
|
||||
if (p == NULL) {
|
||||
if (p == nullptr) {
|
||||
PLOGE("calloc");
|
||||
}
|
||||
return p;
|
||||
@@ -215,7 +214,7 @@ void *xcalloc(size_t nmemb, size_t size) {
|
||||
|
||||
void *xrealloc(void *ptr, size_t size) {
|
||||
void *p = realloc(ptr, size);
|
||||
if (p == NULL) {
|
||||
if (p == nullptr) {
|
||||
PLOGE("realloc");
|
||||
}
|
||||
return p;
|
||||
@@ -297,7 +296,7 @@ ssize_t xreadlink(const char *pathname, char *buf, size_t bufsiz) {
|
||||
}
|
||||
|
||||
ssize_t xreadlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz) {
|
||||
ssize_t ret = syscall(__NR_readlinkat, dirfd, pathname, buf, bufsiz);
|
||||
ssize_t ret = readlinkat(dirfd, pathname, buf, bufsiz);
|
||||
if (ret == -1) {
|
||||
PLOGE("readlinkat %s", pathname);
|
||||
} else {
|
||||
@@ -315,7 +314,7 @@ int xsymlink(const char *target, const char *linkpath) {
|
||||
}
|
||||
|
||||
int xsymlinkat(const char *target, int newdirfd, const char *linkpath) {
|
||||
int ret = (int) syscall(__NR_symlinkat, target, newdirfd, linkpath);
|
||||
int ret = symlinkat(target, newdirfd, linkpath);
|
||||
if (ret == -1) {
|
||||
PLOGE("symlinkat %s->%s", target, linkpath);
|
||||
}
|
||||
@@ -323,7 +322,7 @@ int xsymlinkat(const char *target, int newdirfd, const char *linkpath) {
|
||||
}
|
||||
|
||||
int xlinkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags) {
|
||||
int ret = (int) syscall(__NR_linkat, olddirfd, oldpath, newdirfd, newpath, flags);
|
||||
int ret = linkat(olddirfd, oldpath, newdirfd, newpath, flags);
|
||||
if (ret == -1) {
|
||||
PLOGE("linkat %s->%s", oldpath, newpath);
|
||||
}
|
||||
@@ -422,7 +421,7 @@ int xpoll(struct pollfd *fds, nfds_t nfds, int timeout) {
|
||||
}
|
||||
|
||||
int xinotify_init1(int flags) {
|
||||
int ret = syscall(__NR_inotify_init1, flags);
|
||||
int ret = inotify_init1(flags);
|
||||
if (ret == -1) {
|
||||
PLOGE("inotify_init1");
|
||||
}
|
||||
|
Reference in New Issue
Block a user