Rewrite magiskhide

This commit is contained in:
topjohnwu
2017-04-06 06:12:29 +08:00
parent f476daa041
commit 8f6b33d790
17 changed files with 447 additions and 427 deletions

View File

@ -6,8 +6,14 @@
*
*/
#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "utils.h"
@ -15,7 +21,54 @@ FILE *xfopen(const char *pathname, const char *mode) {
FILE *fp = fopen(pathname, mode);
if (fp == NULL) {
PLOGE("fopen");
exit(1);
}
return fp;
}
}
int xopen(const char *pathname, int flags) {
int fd = open(pathname, flags);
if (fd < 0) {
PLOGE("open");
}
return fd;
}
ssize_t xwrite(int fd, const void *buf, size_t count) {
if (count != write(fd, buf, count)) {
PLOGE("write");
}
return count;
}
// Read error other than EOF
ssize_t xread(int fd, void *buf, size_t count) {
int ret = read(fd, buf, count);
if (ret < 0) {
PLOGE("read");
}
return ret;
}
// Read exact same size as count
ssize_t xxread(int fd, void *buf, size_t count) {
if (count != read(fd, buf, count)) {
PLOGE("read");
}
return count;
}
int xpipe(int pipefd[2]) {
if (pipe(pipefd) == -1) {
PLOGE("pipe");
exit(1);
}
return 0;
}
int xsetns(int fd, int nstype) {
if (setns(fd, nstype) == -1) {
PLOGE("setns");
}
return 0;
}