Cleanup headers

This commit is contained in:
topjohnwu
2019-11-19 02:04:47 -05:00
parent 7681fde4d0
commit 9aff1a57d3
11 changed files with 45 additions and 89 deletions

View File

@ -1,5 +1,8 @@
#pragma once
#include <functional>
#include <string_view>
#define do_align(p, a) (((p) + (a) - 1) / (a) * (a))
#define align_off(p, a) (do_align(p, a) - (p))
@ -8,10 +11,6 @@ struct file_attr {
char con[128];
};
#ifdef __cplusplus
extern "C" {
#endif
ssize_t fd_path(int fd, char *path, size_t size);
int fd_pathat(int dirfd, const char *name, char *path, size_t size);
int mkdirs(const char *pathname, mode_t mode);
@ -32,12 +31,6 @@ void fd_full_read(int fd, void **buf, size_t *size);
void full_read(const char *filename, void **buf, size_t *size);
void write_zero(int fd, size_t size);
#ifdef __cplusplus
}
#include <functional>
#include <string_view>
void file_readline(const char *file, const std::function<bool (std::string_view)> &fn, bool trim = false);
void parse_prop_file(const char *file, const std::function
<bool(std::string_view, std::string_view)> &fn);
@ -81,5 +74,3 @@ void mmap_rw(const char *filename, B &buf, L &sz) {
buf = (B) __mmap(filename, &__sz, true);
sz = __sz;
}
#endif

View File

@ -1,15 +1,10 @@
/* logging.h - Error handling and logging
*/
#pragma once
#include <errno.h>
#include <stdarg.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
__BEGIN_DECLS
typedef enum {
L_DEBUG,
@ -43,6 +38,4 @@ void cmdline_logging();
int log_handler(log_type t, const char *fmt, ...);
#ifdef __cplusplus
}
#endif
__END_DECLS

View File

@ -18,8 +18,6 @@
#define SEPOL_PROC_DOMAIN "magisk"
#define SEPOL_FILE_DOMAIN "magisk_file"
__BEGIN_DECLS
extern void (*freecon)(char *con);
extern int (*setcon)(const char *con);
extern int (*getfilecon)(const char *path, char **con);
@ -35,5 +33,3 @@ void selinux_builtin_impl();
void dload_selinux();
void restorecon();
void restore_rootcon();
__END_DECLS

View File

@ -1,30 +1,11 @@
#pragma once
#define UID_ROOT 0
#define UID_SHELL 2000
#ifdef __cplusplus
extern "C" {
#endif
int fork_dont_care();
int fork_no_zombie();
int strend(const char *s1, const char *s2);
char *rtrim(char *str);
void init_argv0(int argc, char **argv);
void set_nice_name(const char *name);
int parse_int(const char *s);
uint32_t binary_gcd(uint32_t u, uint32_t v);
int switch_mnt_ns(int pid);
#ifdef __cplusplus
}
#include <string>
#include <functional>
#include <string_view>
void gen_rand_str(char *buf, int len, bool varlen = true);
#define UID_ROOT 0
#define UID_SHELL 2000
#define str_contains(s, ss) ((ss) != nullptr && (s).find(ss) != std::string::npos)
#define str_starts(s, ss) ((ss) != nullptr && (s).compare(0, strlen(ss), ss) == 0)
@ -78,8 +59,8 @@ reversed_container<T> reversed(T &base) {
return reversed_container<T>(base);
}
int parse_int(const char *s);
static inline int parse_int(std::string s) { return parse_int(s.data()); }
static inline int parse_int(std::string_view s) { return parse_int(s.data()); }
int new_daemon_thread(void *(*start_routine) (void *), void *arg = nullptr,
@ -115,5 +96,12 @@ int exec_command_sync(Args &&...args) {
}
bool ends_with(const std::string_view &s1, const std::string_view &s2);
#endif
int fork_dont_care();
int fork_no_zombie();
int strend(const char *s1, const char *s2);
char *rtrim(char *str);
void init_argv0(int argc, char **argv);
void set_nice_name(const char *name);
uint32_t binary_gcd(uint32_t u, uint32_t v);
int switch_mnt_ns(int pid);
void gen_rand_str(char *buf, int len, bool varlen = true);

View File

@ -19,8 +19,6 @@
#define endmntent __endmntent
#define hasmntopt __hasmntopt
__BEGIN_DECLS
ssize_t __getline(char **lineptr, size_t *n, FILE *stream);
ssize_t __getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
struct mntent *__getmntent_r(FILE* fp, struct mntent* e, char* buf, int buf_len);
@ -60,5 +58,3 @@ static inline int __linkat(int olddirfd, const char *oldpath,
static inline int __inotify_init1(int flags) {
return syscall(__NR_inotify_init1, flags);
}
__END_DECLS

View File

@ -1,11 +1,9 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
FILE *xfopen(const char *pathname, const char *mode);
FILE *xfdopen(int fd, const char *mode);
int xopen(const char *pathname, int flags);
int xopen(const char *pathname, int flags, mode_t mode);
int xopenat(int dirfd, const char *pathname, int flags);
ssize_t xwrite(int fd, const void *buf, size_t count);
ssize_t xread(int fd, void *buf, size_t count);
@ -22,9 +20,9 @@ int xbind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int xconnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int xlisten(int sockfd, int backlog);
int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
void *xmalloc(size_t size);
void *xcalloc(size_t nmemb, size_t size);
void *xrealloc(void *ptr, size_t size);
extern "C" void *xmalloc(size_t size);
extern "C" void *xcalloc(size_t nmemb, size_t size);
extern "C" void *xrealloc(void *ptr, size_t size);
ssize_t xsendmsg(int sockfd, const struct msghdr *msg, int flags);
ssize_t xrecvmsg(int sockfd, struct msghdr *msg, int flags);
int xpthread_create(pthread_t *thread, const pthread_attr_t *attr,
@ -54,11 +52,3 @@ pid_t xfork();
int xpoll(struct pollfd *fds, nfds_t nfds, int timeout);
int xinotify_init1(int flags);
#ifdef __cplusplus
}
int xopen(const char *pathname, int flags);
int xopen(const char *pathname, int flags, mode_t mode);
#endif