Reduce duplicate code for MagiskBoot

This commit is contained in:
topjohnwu
2017-04-28 21:48:38 +08:00
parent 62fe92d922
commit d3d5703f3f
15 changed files with 145 additions and 129 deletions

View File

@ -18,7 +18,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <selinux/selinux.h>
#include <sys/mman.h>
#include <sys/sendfile.h>
#include "magisk.h"
#include "utils.h"
@ -31,7 +32,7 @@ FILE *xfopen(const char *pathname, const char *mode) {
return fp;
}
int xopen(const char *pathname, int flags) {
int xopen2(const char *pathname, int flags) {
int fd = open(pathname, flags);
if (fd < 0) {
PLOGE("open: %s", pathname);
@ -39,6 +40,14 @@ int xopen(const char *pathname, int flags) {
return fd;
}
int xopen3(const char *pathname, int flags, mode_t mode) {
int fd = open(pathname, flags, mode);
if (fd < 0) {
PLOGE("open: %s", pathname);
}
return fd;
}
ssize_t xwrite(int fd, const void *buf, size_t count) {
int ret = write(fd, buf, count);
if (count != ret) {
@ -106,14 +115,6 @@ pid_t xsetsid() {
return pid;
}
int xsetcon(char *context) {
int ret = setcon(context);
if (ret == -1) {
PLOGE("setcon: %s", context);
}
return ret;
}
int xsocket(int domain, int type, int protocol) {
int fd = socket(domain, type, protocol);
if (fd == -1) {
@ -280,4 +281,21 @@ int xmkdir(const char *pathname, mode_t mode) {
return ret;
}
void *xmmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset) {
void *ret = mmap(addr, length, prot, flags, fd, offset);
if (ret == MAP_FAILED) {
PLOGE("mmap");
}
return ret;
}
ssize_t xsendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
ssize_t ret = sendfile(out_fd, in_fd, offset, count);
if (count != ret) {
PLOGE("sendfile");
}
return ret;
}