mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 21:27:41 +02:00
Fix several small issues
This commit is contained in:
@ -308,7 +308,7 @@ int cp_afc(const char *source, const char *target) {
|
||||
int clone_dir(const char *source, const char *target) {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
char *s_path, *t_path, *con;
|
||||
char *s_path, *t_path;
|
||||
|
||||
if (!(dir = xopendir(source)))
|
||||
return 1;
|
||||
@ -316,13 +316,8 @@ int clone_dir(const char *source, const char *target) {
|
||||
s_path = xmalloc(PATH_MAX);
|
||||
t_path = xmalloc(PATH_MAX);
|
||||
|
||||
struct stat buf;
|
||||
xstat(source, &buf);
|
||||
mkdir_p(target, buf.st_mode & 0777);
|
||||
xchmod(target, buf.st_mode & 0777);
|
||||
lgetfilecon(source, &con);
|
||||
lsetfilecon(target, con);
|
||||
free(con);
|
||||
mkdir_p(target, 0755);
|
||||
clone_attr(source, target);
|
||||
|
||||
while ((entry = xreaddir(dir))) {
|
||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||
@ -380,3 +375,14 @@ int rm_rf(const char *target) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void clone_attr(const char *source, const char *target) {
|
||||
struct stat buf;
|
||||
xstat(source, &buf);
|
||||
chmod(target, buf.st_mode & 0777);
|
||||
chown(target, buf.st_uid, buf.st_gid);
|
||||
char *con;
|
||||
lgetfilecon(source, &con);
|
||||
lsetfilecon(target, con);
|
||||
free(con);
|
||||
}
|
||||
|
@ -88,5 +88,6 @@ int open_new(const char *filename);
|
||||
int cp_afc(const char *source, const char *target);
|
||||
int clone_dir(const char *source, const char *target);
|
||||
int rm_rf(const char *target);
|
||||
void clone_attr(const char *source, const char *target);
|
||||
|
||||
#endif
|
||||
|
@ -2,6 +2,7 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
@ -49,3 +50,12 @@ void vec_deep_destroy(struct vector *v) {
|
||||
}
|
||||
vec_destroy(v);
|
||||
}
|
||||
|
||||
struct vector *vec_dup(struct vector *v) {
|
||||
struct vector *ret = malloc(sizeof(*ret));
|
||||
vec_size(ret) = vec_size(v);
|
||||
vec_cap(ret) = vec_cap(v);
|
||||
vec_entry(v) = malloc(sizeof(void*) * vec_cap(ret));
|
||||
memcpy(vec_entry(ret), vec_entry(v), sizeof(void*) * vec_cap(ret));
|
||||
return ret;
|
||||
}
|
||||
|
@ -11,11 +11,14 @@ struct vector {
|
||||
size_t cap;
|
||||
void **data;
|
||||
};
|
||||
|
||||
void vec_init(struct vector *v);
|
||||
void vec_push_back(struct vector *v, void *p);
|
||||
void vec_sort(struct vector *v, int (*compar)(const void *, const void *));
|
||||
void vec_destroy(struct vector *v);
|
||||
void vec_deep_destroy(struct vector *v);
|
||||
struct vector *vec_dup(struct vector *v);
|
||||
|
||||
#define vec_size(v) (v)->size
|
||||
#define vec_cap(v) (v)->cap
|
||||
#define vec_entry(v) (v)->data
|
||||
|
Reference in New Issue
Block a user