Fully migrate Magisk to C++

This commit is contained in:
topjohnwu
2018-11-04 03:38:06 -05:00
parent 4351de503f
commit cda57dd4b4
27 changed files with 548 additions and 607 deletions

View File

@@ -9,7 +9,6 @@ LOCAL_SRC_FILES := \
selinux.cpp \
logging.cpp \
xwrap.cpp \
vector.c \
legacy.c
vector.c
include $(BUILD_STATIC_LIBRARY)

View File

@@ -66,6 +66,15 @@ public:
T* _node;
};
T& operator = (const T& a) {
_size = a._size;
_capacity = a._capacity;
_data = new T[_capacity];
for(int i = 0; i < _size; ++i)
_data[i] = (T&&) a[i];
return *this;
}
iterator begin() const { return iterator(_data); }
iterator end() const { return iterator(_data + _size); }
@@ -149,7 +158,8 @@ private:
_capacity *= 2;
T* temp = _data;
_data = new T[_capacity];
for(int i = 0; i < _size; ++i) _data[i] = (T&&) temp[i];
for(int i = 0; i < _size; ++i)
_data[i] = (T&&) temp[i];
delete [] temp;
}
};

View File

@@ -4,7 +4,6 @@
extern "C" {
#endif
extern void (*freecon)(char * con);
extern int (*setcon)(const char * con);
extern int (*getfilecon)(const char *path, char ** con);

View File

@@ -18,8 +18,6 @@ int file_to_array(const char* filename, Array<char *> &arr);
extern "C" {
#endif
#include "vector.h"
#define UID_SHELL (get_shell_uid())
#define UID_ROOT 0
#define UID_SYSTEM (get_system_uid())
@@ -86,8 +84,6 @@ int xpoll(struct pollfd *fds, nfds_t nfds, int timeout);
unsigned get_shell_uid();
unsigned get_system_uid();
unsigned get_radio_uid();
int file_to_vector(const char* filename, struct vector *v);
int vector_to_file(const char* filename, struct vector *v);
ssize_t fdgets(char *buf, size_t size, int fd);
int is_num(const char *s);
int exec_array(int err, int *fd, void (*cb)(void), const char *argv[]);

View File

@@ -1,41 +0,0 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "utils.h"
#include "logging.h"
/* All the string should be freed manually!! */
int file_to_vector(const char* filename, struct vector *v) {
if (access(filename, R_OK) != 0)
return 1;
char *line = NULL;
size_t len = 0;
ssize_t read;
FILE *fp = xfopen(filename, "r");
if (fp == NULL)
return 1;
while ((read = getline(&line, &len, fp)) != -1) {
// Remove end newline
if (line[read - 1] == '\n')
line[read - 1] = '\0';
vec_push_back(v, line);
line = NULL;
}
fclose(fp);
return 0;
}
int vector_to_file(const char *filename, struct vector *v) {
FILE *fp = xfopen(filename, "w");
if (fp == NULL)
return 1;
char *line;
vec_for_each(v, line) {
fprintf(fp, "%s\n", line);
}
fclose(fp);
return 0;
}