From 6339ba6bfb136e07add3fafb61753accab1f0988 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 3 Nov 2018 03:06:01 -0400 Subject: [PATCH] Upgrade libutils to C++ --- native/jni/magiskhide/hide_utils.cpp | 2 +- native/jni/magiskhide/proc_monitor.cpp | 2 +- native/jni/utils/Android.mk | 13 +- native/jni/utils/{file.c => file.cpp} | 38 ++++- native/jni/utils/include/list.h | 43 ----- native/jni/utils/include/selinux.h | 10 +- native/jni/utils/include/utils.h | 4 +- native/jni/utils/include/utils.hpp | 6 - native/jni/utils/legacy.c | 128 +++++++++++++++ native/jni/utils/list.c | 39 ----- native/jni/utils/{logging.c => logging.cpp} | 0 native/jni/utils/{misc.c => misc.cpp} | 165 ++------------------ native/jni/utils/{selinux.c => selinux.cpp} | 26 ++- native/jni/utils/utils.cpp | 25 --- native/jni/utils/{xwrap.c => xwrap.cpp} | 3 +- 15 files changed, 200 insertions(+), 304 deletions(-) rename native/jni/utils/{file.c => file.cpp} (91%) delete mode 100644 native/jni/utils/include/list.h delete mode 100644 native/jni/utils/include/utils.hpp create mode 100644 native/jni/utils/legacy.c delete mode 100644 native/jni/utils/list.c rename native/jni/utils/{logging.c => logging.cpp} (100%) rename native/jni/utils/{misc.c => misc.cpp} (50%) rename native/jni/utils/{selinux.c => selinux.cpp} (81%) delete mode 100644 native/jni/utils/utils.cpp rename native/jni/utils/{xwrap.c => xwrap.cpp} (99%) diff --git a/native/jni/magiskhide/hide_utils.cpp b/native/jni/magiskhide/hide_utils.cpp index 9aece44e4..f383190cb 100644 --- a/native/jni/magiskhide/hide_utils.cpp +++ b/native/jni/magiskhide/hide_utils.cpp @@ -9,7 +9,7 @@ #include #include "magisk.h" -#include "utils.hpp" +#include "utils.h" #include "resetprop.h" #include "magiskhide.h" #include "daemon.h" diff --git a/native/jni/magiskhide/proc_monitor.cpp b/native/jni/magiskhide/proc_monitor.cpp index d54f3a32d..447bda029 100644 --- a/native/jni/magiskhide/proc_monitor.cpp +++ b/native/jni/magiskhide/proc_monitor.cpp @@ -18,7 +18,7 @@ #include "magisk.h" #include "daemon.h" -#include "utils.hpp" +#include "utils.h" #include "magiskhide.h" #include "flags.h" diff --git a/native/jni/utils/Android.mk b/native/jni/utils/Android.mk index b44d3d6cb..85c2a88f5 100644 --- a/native/jni/utils/Android.mk +++ b/native/jni/utils/Android.mk @@ -4,13 +4,12 @@ include $(CLEAR_VARS) LOCAL_MODULE:= libutils LOCAL_C_INCLUDES := jni/include $(LIBUTILS) LOCAL_SRC_FILES := \ - utils.cpp \ - file.c \ - list.c \ - misc.c \ + file.cpp \ + misc.cpp \ + selinux.cpp \ + logging.cpp \ + xwrap.cpp \ vector.c \ - selinux.c \ - logging.c \ - xwrap.c + legacy.c include $(BUILD_STATIC_LIBRARY) diff --git a/native/jni/utils/file.c b/native/jni/utils/file.cpp similarity index 91% rename from native/jni/utils/file.c rename to native/jni/utils/file.cpp index ed6f1dfe0..715350e6e 100644 --- a/native/jni/utils/file.c +++ b/native/jni/utils/file.cpp @@ -1,4 +1,4 @@ -/* file.c - Contains all files related utilities +/* file.cpp - Contains all files related utilities */ #include @@ -15,7 +15,7 @@ #include "utils.h" #include "selinux.h" -const char **excl_list = NULL; +const char **excl_list = nullptr; static int is_excl(const char *name) { if (excl_list) @@ -62,7 +62,7 @@ void in_order_walk(int dirfd, void (*callback)(int, struct dirent*)) { struct dirent *entry; int newfd; DIR *dir = fdopendir(dirfd); - if (dir == NULL) return; + if (dir == nullptr) return; while ((entry = xreaddir(dir))) { if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) @@ -176,7 +176,7 @@ void cp_afc(const char *source, const char *destination) { if (S_ISREG(a.st.st_mode)) { src = xopen(source, O_RDONLY); dest = xopen(destination, O_WRONLY | O_CREAT | O_TRUNC); - xsendfile(dest, src, NULL, a.st.st_size); + xsendfile(dest, src, nullptr, a.st.st_size); close(src); close(dest); } else if (S_ISLNK(a.st.st_mode)) { @@ -321,7 +321,7 @@ static void _mmap(int rw, const char *filename, void **buf, size_t *size) { ioctl(fd, BLKGETSIZE64, size); else *size = st.st_size; - *buf = *size > 0 ? xmmap(NULL, *size, PROT_READ | (rw ? PROT_WRITE : 0), MAP_SHARED, fd, 0) : NULL; + *buf = *size > 0 ? xmmap(nullptr, *size, PROT_READ | (rw ? PROT_WRITE : 0), MAP_SHARED, fd, 0) : nullptr; close(fd); } @@ -344,7 +344,7 @@ void fd_full_read(int fd, void **buf, size_t *size) { void full_read(const char *filename, void **buf, size_t *size) { int fd = xopen(filename, O_RDONLY | O_CLOEXEC); if (fd < 0) { - *buf = NULL; + *buf = nullptr; *size = 0; return; } @@ -355,7 +355,7 @@ void full_read(const char *filename, void **buf, size_t *size) { void full_read_at(int dirfd, const char *filename, void **buf, size_t *size) { int fd = xopenat(dirfd, filename, O_RDONLY | O_CLOEXEC); if (fd < 0) { - *buf = NULL; + *buf = nullptr; *size = 0; return; } @@ -377,7 +377,7 @@ void stream_full_read(int fd, void **buf, size_t *size) { cap *= 2; *buf = realloc(*buf, cap); } - memcpy(*buf + *size, tmp, read); + memcpy((uint8_t *) *buf + *size, tmp, read); *size += read; } } @@ -387,3 +387,25 @@ void write_zero(int fd, size_t size) { ftruncate(fd, pos + size); lseek(fd, pos + size, SEEK_SET); } + +int file_to_array(const char *filename, Array &arr) { + if (access(filename, R_OK) != 0) + return 1; + char *line = nullptr; + size_t len = 0; + ssize_t read; + + FILE *fp = xfopen(filename, "r"); + if (fp == nullptr) + return 1; + + while ((read = getline(&line, &len, fp)) != -1) { + // Remove end newline + if (line[read - 1] == '\n') + line[read - 1] = '\0'; + arr.push_back(line); + line = nullptr; + } + fclose(fp); + return 0; +} diff --git a/native/jni/utils/include/list.h b/native/jni/utils/include/list.h deleted file mode 100644 index 3fe1aca12..000000000 --- a/native/jni/utils/include/list.h +++ /dev/null @@ -1,43 +0,0 @@ -/* list.h - Double link list implementation - */ - -#ifndef _LIST_H_ -#define _LIST_H_ - -#include - -struct list_head { - struct list_head *next; - struct list_head *prev; -}; - -void init_list_head(struct list_head *head); -void list_insert(struct list_head *pos, struct list_head *node); -void list_insert_end(struct list_head *head, struct list_head *node); -struct list_head *list_pop(struct list_head *pos); -struct list_head *list_pop_end(struct list_head *head); - -#define list_entry(pos, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (pos); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) - -#define list_for_each(ptr, head, type, member) \ - ptr = list_entry((head)->next, type, member); \ - for (struct list_head *__ = (head)->next; __ != (head); __ = __->next, ptr = list_entry(__, type, member)) - -#define list_for_each_r(ptr, head, type, member) \ - ptr = list_entry((head)->prev, type, member); \ - for (struct list_head *__ = (head)->prev; __ != (head); __ = __->prev, ptr = list_entry(__, type, member)) - -#define list_destory(head, type, member, func) ({ \ - struct list_head *node = head->next; \ - while(node != head) { \ - node = node->next; \ - if (func) func(list_entry(node->prev, line_list, pos)); \ - free(list_entry(node->prev, line_list, pos)); \ - } \ - head->next = head; \ - head->prev = head; \ -}) - -#endif diff --git a/native/jni/utils/include/selinux.h b/native/jni/utils/include/selinux.h index 0a51b0d12..73389611b 100644 --- a/native/jni/utils/include/selinux.h +++ b/native/jni/utils/include/selinux.h @@ -1,6 +1,10 @@ - #pragma once +#ifdef __cplusplus +extern "C" { +#endif + + extern void (*freecon)(char * con); extern int (*setcon)(const char * con); extern int (*getfilecon)(const char *path, char ** con); @@ -10,3 +14,7 @@ extern int (*lsetfilecon)(const char *path, const char * con); void dload_selinux(); void restorecon(); + +#ifdef __cplusplus +} +#endif diff --git a/native/jni/utils/include/utils.h b/native/jni/utils/include/utils.h index 2ac516af9..07d07b008 100644 --- a/native/jni/utils/include/utils.h +++ b/native/jni/utils/include/utils.h @@ -12,6 +12,9 @@ #include #ifdef __cplusplus +// C++ only +#include "array.h" +int file_to_array(const char* filename, Array &arr); extern "C" { #endif @@ -92,7 +95,6 @@ int exec_command(int err, int *fd, void (*setenv)(struct vector*), const char *a int exec_command_sync(char *const argv0, ...); int switch_mnt_ns(int pid); int fork_dont_care(); -void wait_till_exists(const char *target); void gen_rand_str(char *buf, int len); int strend(const char *s1, const char *s2); diff --git a/native/jni/utils/include/utils.hpp b/native/jni/utils/include/utils.hpp deleted file mode 100644 index 0218eaa25..000000000 --- a/native/jni/utils/include/utils.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "utils.h" -#include "array.h" - -int file_to_array(const char* filename, Array &arr); \ No newline at end of file diff --git a/native/jni/utils/legacy.c b/native/jni/utils/legacy.c new file mode 100644 index 000000000..0e6137174 --- /dev/null +++ b/native/jni/utils/legacy.c @@ -0,0 +1,128 @@ +#include +#include +#include + +#include "utils.h" +#include "logging.h" + +/* + fd == NULL -> Ignore output + *fd < 0 -> Open pipe and set *fd to the read end + *fd >= 0 -> STDOUT (or STDERR) will be redirected to *fd + *setenv -> A callback function which sets up a vector of environment variables +*/ +int exec_array(int err, int *fd, void (*setenv)(struct vector *), char *const *argv) { + int pipefd[2], writeEnd = -1; + + if (fd) { + if (*fd < 0) { + if (xpipe2(pipefd, O_CLOEXEC) == -1) + return -1; + writeEnd = pipefd[1]; + } else { + writeEnd = *fd; + } + } + + // Setup environment + char **envp; + struct vector env; + vec_init(&env); + if (setenv) { + setenv(&env); + envp = (char **) vec_entry(&env); + } else { + extern char **environ; + envp = environ; + } + + int pid = xfork(); + if (pid != 0) { + if (fd && *fd < 0) { + // Give the read end and close write end + *fd = pipefd[0]; + close(pipefd[1]); + } + vec_deep_destroy(&env); + return pid; + } + + if (fd) { + xdup2(writeEnd, STDOUT_FILENO); + if (err) + xdup2(writeEnd, STDERR_FILENO); + } + + environ = envp; + execvp(argv[0], argv); + PLOGE("execvp %s", argv[0]); + return -1; +} + +static int v_exec_command(int err, int *fd, void (*setenv)(struct vector*), const char *argv0, va_list argv) { + // Collect va_list into vector + struct vector args; + vec_init(&args); + vec_push_back(&args, strdup(argv0)); + for (void *arg = va_arg(argv, void*); arg; arg = va_arg(argv, void*)) + vec_push_back(&args, strdup(arg)); + vec_push_back(&args, NULL); + int pid = exec_array(err, fd, setenv, (char **) vec_entry(&args)); + vec_deep_destroy(&args); + return pid; +} + +int exec_command_sync(char *const argv0, ...) { + va_list argv; + va_start(argv, argv0); + int pid, status; + pid = v_exec_command(0, NULL, NULL, argv0, argv); + va_end(argv); + if (pid < 0) + return pid; + waitpid(pid, &status, 0); + return WEXITSTATUS(status); +} + +int exec_command(int err, int *fd, void (*setenv)(struct vector*), const char *argv0, ...) { + va_list argv; + va_start(argv, argv0); + int pid = v_exec_command(err, fd, setenv, argv0, argv); + va_end(argv); + return pid; +} + +/* 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; +} \ No newline at end of file diff --git a/native/jni/utils/list.c b/native/jni/utils/list.c deleted file mode 100644 index c54d532c8..000000000 --- a/native/jni/utils/list.c +++ /dev/null @@ -1,39 +0,0 @@ -/* list.h - Double link list implementation - */ - -#include "list.h" - -void init_list_head(struct list_head *head) { - head->next = head; - head->prev = head; -} - -void list_insert(struct list_head *pos, struct list_head *node) { - // First construct our new node - node->next = pos->next; - node->prev = pos; - // Maintain the list - pos->next->prev = node; - pos->next = node; -} - -void list_insert_end(struct list_head *head, struct list_head *node) { - list_insert(head->prev, node); -} - -struct list_head *list_pop(struct list_head *pos) { - struct list_head *ret; - ret = pos->prev; - // Maintain the list - pos->prev->next = pos->next; - pos->next->prev = pos->prev; - // Remove references - pos->next = pos; - pos->prev = pos; - // Return the previous node in the list - return ret; -} - -struct list_head *list_pop_end(struct list_head *head) { - return list_pop(head->prev); -} diff --git a/native/jni/utils/logging.c b/native/jni/utils/logging.cpp similarity index 100% rename from native/jni/utils/logging.c rename to native/jni/utils/logging.cpp diff --git a/native/jni/utils/misc.c b/native/jni/utils/misc.cpp similarity index 50% rename from native/jni/utils/misc.c rename to native/jni/utils/misc.cpp index 4c79908ec..b3d985fb9 100644 --- a/native/jni/utils/misc.c +++ b/native/jni/utils/misc.cpp @@ -1,23 +1,15 @@ -/* misc.c - Store all functions that are unable to be catagorized clearly +/* misc.cpp - Store all functions that are unable to be catagorized clearly */ - -#define _GNU_SOURCE + #include #include #include -#include #include #include -#include -#include #include -#include #include #include -#include #include -#include -#include #include #include "logging.h" @@ -25,7 +17,7 @@ unsigned get_shell_uid() { struct passwd* ppwd = getpwnam("shell"); - if (NULL == ppwd) + if (nullptr == ppwd) return 2000; return ppwd->pw_uid; @@ -33,7 +25,7 @@ unsigned get_shell_uid() { unsigned get_system_uid() { struct passwd* ppwd = getpwnam("system"); - if (NULL == ppwd) + if (nullptr == ppwd) return 1000; return ppwd->pw_uid; @@ -41,47 +33,12 @@ unsigned get_system_uid() { unsigned get_radio_uid() { struct passwd* ppwd = getpwnam("radio"); - if (NULL == ppwd) + if (nullptr == ppwd) return 1001; return ppwd->pw_uid; } -/* 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; -} - /* Check if the string only contains digits */ int is_num(const char *s) { int len = strlen(s); @@ -110,93 +67,6 @@ ssize_t fdgets(char *buf, const size_t size, int fd) { return len; } -/* - fd == NULL -> Ignore output - *fd < 0 -> Open pipe and set *fd to the read end - *fd >= 0 -> STDOUT (or STDERR) will be redirected to *fd - *setenv -> A callback function which sets up a vector of environment variables -*/ -int exec_array(int err, int *fd, void (*setenv)(struct vector *), char *const *argv) { - int pipefd[2], writeEnd = -1; - - if (fd) { - if (*fd < 0) { - if (xpipe2(pipefd, O_CLOEXEC) == -1) - return -1; - writeEnd = pipefd[1]; - } else { - writeEnd = *fd; - } - } - - // Setup environment - char **envp; - struct vector env; - vec_init(&env); - if (setenv) { - setenv(&env); - envp = (char **) vec_entry(&env); - } else { - extern char **environ; - envp = environ; - } - - int pid = xfork(); - if (pid != 0) { - if (fd && *fd < 0) { - // Give the read end and close write end - *fd = pipefd[0]; - close(pipefd[1]); - } - vec_deep_destroy(&env); - return pid; - } - - if (fd) { - xdup2(writeEnd, STDOUT_FILENO); - if (err) - xdup2(writeEnd, STDERR_FILENO); - } - - environ = envp; - execvp(argv[0], argv); - PLOGE("execvp %s", argv[0]); - return -1; -} - -static int v_exec_command(int err, int *fd, void (*setenv)(struct vector*), const char *argv0, va_list argv) { - // Collect va_list into vector - struct vector args; - vec_init(&args); - vec_push_back(&args, strdup(argv0)); - for (void *arg = va_arg(argv, void*); arg; arg = va_arg(argv, void*)) - vec_push_back(&args, strdup(arg)); - vec_push_back(&args, NULL); - int pid = exec_array(err, fd, setenv, (char **) vec_entry(&args)); - vec_deep_destroy(&args); - return pid; -} - -int exec_command_sync(char *const argv0, ...) { - va_list argv; - va_start(argv, argv0); - int pid, status; - pid = v_exec_command(0, NULL, NULL, argv0, argv); - va_end(argv); - if (pid < 0) - return pid; - waitpid(pid, &status, 0); - return WEXITSTATUS(status); -} - -int exec_command(int err, int *fd, void (*setenv)(struct vector*), const char *argv0, ...) { - va_list argv; - va_start(argv, argv0); - int pid = v_exec_command(err, fd, setenv, argv0, argv); - va_end(argv); - return pid; -} - int switch_mnt_ns(int pid) { char mnt[32]; snprintf(mnt, sizeof(mnt), "/proc/%d/ns/mnt", pid); @@ -214,7 +84,7 @@ int switch_mnt_ns(int pid) { int fork_dont_care() { int pid = xfork(); if (pid) { - waitpid(pid, NULL, 0); + waitpid(pid, nullptr, 0); return pid; } else if ((pid = xfork())) { exit(0); @@ -222,23 +92,6 @@ int fork_dont_care() { return 0; } -void wait_till_exists(const char *target) { - if (access(target, F_OK) == 0) - return; - int fd = inotify_init(); - char *dir = dirname(target); - char crap[PATH_MAX]; - inotify_add_watch(fd, dir, IN_CREATE); - while (1) { - struct inotify_event event; - read(fd, &event, sizeof(event)); - read(fd, crap, event.len); - if (access(target, F_OK) == 0) - break; - } - close(fd); -} - void gen_rand_str(char *buf, int len) { const char base[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; int urandom; @@ -278,7 +131,7 @@ ssize_t __getdelim(char **lineptr, size_t *n, int delim, FILE *stream) { if (!*lineptr) { *n = MIN_CHUNK; - *lineptr = malloc(*n); + *lineptr = (char *) malloc(*n); if (!*lineptr) { errno = ENOMEM; return -1; @@ -290,7 +143,7 @@ ssize_t __getdelim(char **lineptr, size_t *n, int delim, FILE *stream) { while (1) { int save_errno; - register int c = getc(stream); + int c = getc(stream); save_errno = errno; @@ -301,7 +154,7 @@ ssize_t __getdelim(char **lineptr, size_t *n, int delim, FILE *stream) { *n += MIN_CHUNK; nchars_avail = *n + *lineptr - read_pos; - *lineptr = realloc(*lineptr, *n); + *lineptr = (char *) realloc(*lineptr, *n); if (!*lineptr) { errno = ENOMEM; return -1; diff --git a/native/jni/utils/selinux.c b/native/jni/utils/selinux.cpp similarity index 81% rename from native/jni/utils/selinux.c rename to native/jni/utils/selinux.cpp index 823590a0a..408437008 100644 --- a/native/jni/utils/selinux.c +++ b/native/jni/utils/selinux.cpp @@ -9,20 +9,18 @@ #define UNLABEL_CON "u:object_r:unlabeled:s0" #define SYSTEM_CON "u:object_r:system_file:s0" #define ADB_CON "u:object_r:adb_data_file:s0" -#define MAGISK_CON "u:object_r:"SEPOL_FILE_DOMAIN":s0" +#define MAGISK_CON "u:object_r:" SEPOL_FILE_DOMAIN ":s0" // Stub implementations -static char *empty_str = ""; +static void v_s(char *) {} -static void v_s(char *s) {} +static int i_s(const char *) { return 0; } -static int i_s(const char *s) { return 0; } +static int i_ss(const char *, const char *) { return 0; } -static int i_ss(const char *s, const char * ss) { return 0; } - -static int i_ssp(const char *s, char ** sp) { - *sp = empty_str; +static int i_ssp(const char *, char ** sp) { + *sp = (char *) xcalloc(1, 1); return 0; } @@ -39,12 +37,12 @@ void dload_selinux() { void *handle = dlopen("libselinux.so", RTLD_LAZY); if (handle == NULL) return; - freecon = dlsym(handle, "freecon"); - setcon = dlsym(handle, "setcon"); - getfilecon = dlsym(handle, "getfilecon"); - lgetfilecon = dlsym(handle, "lgetfilecon"); - setfilecon = dlsym(handle, "setfilecon"); - lsetfilecon = dlsym(handle, "lsetfilecon"); + *(void **) &freecon = dlsym(handle, "freecon"); + *(void **) &setcon = dlsym(handle, "setcon"); + *(void **) &getfilecon = dlsym(handle, "getfilecon"); + *(void **) &lgetfilecon = dlsym(handle, "lgetfilecon"); + *(void **) &setfilecon = dlsym(handle, "setfilecon"); + *(void **) &lsetfilecon = dlsym(handle, "lsetfilecon"); } static void restore_syscon(int dirfd) { diff --git a/native/jni/utils/utils.cpp b/native/jni/utils/utils.cpp deleted file mode 100644 index 3f3a5b2d0..000000000 --- a/native/jni/utils/utils.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - -#include "utils.hpp" - -int file_to_array(const char *filename, Array &arr) { - 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'; - arr.push_back(line); - line = NULL; - } - fclose(fp); - return 0; -} diff --git a/native/jni/utils/xwrap.c b/native/jni/utils/xwrap.cpp similarity index 99% rename from native/jni/utils/xwrap.c rename to native/jni/utils/xwrap.cpp index f50caa0cb..1a6600c12 100644 --- a/native/jni/utils/xwrap.c +++ b/native/jni/utils/xwrap.cpp @@ -1,4 +1,4 @@ -/* xwrap.c - wrappers around existing library functions. +/* xwrap.cpp - wrappers around existing library functions. * * Functions with the x prefix are wrappers that either succeed or log the * error message. They usually have the same arguments and return value @@ -6,7 +6,6 @@ * */ -#define _GNU_SOURCE #include #include #include