Merge pull request 'master' (#36) from YanTheKaller/libublsettings:master into master

Reviewed-on: #36
master v1.32
Dmitry Razumov 1 year ago
commit 9e161b53e1

@ -664,6 +664,20 @@ int yon_char_parsed_check_exist(char **parameters, int size, char *param){
return -1; return -1;
} }
int yon_char_parsed_strstr(char **parameters, int size, char *param){
if (parameters){
for (int i=0;i<size;i++){
if (parameters[i]){
if (!strstr(parameters[i],param))
return i;
} else return -1;
}
}
return -1;
}
int yon_char_parsed_check_repeats(char **parameters, int size, int *first_overlap, int *second_overlap){ int yon_char_parsed_check_repeats(char **parameters, int size, int *first_overlap, int *second_overlap){
if (parameters){ if (parameters){
*first_overlap=0; *first_overlap=0;
@ -2227,7 +2241,9 @@ config_str yon_file_open(char *file_path, int *size){
int yon_file_save(char *file_path, char *text){ int yon_file_save(char *file_path, char *text){
FILE *file = fopen(file_path,"w"); FILE *file = fopen(file_path,"w");
chmod(file_path,0777); struct passwd *user = getpwnam(yon_ubl_root_user_get());
chown(file_path,user->pw_uid,user->pw_gid);
chmod(file_path,0644);
if (file){ if (file){
fputs(text,file); fputs(text,file);
fclose(file); fclose(file);
@ -2241,8 +2257,9 @@ int yon_file_create(char *path, char *name, int rules){
char *full_path = yon_char_unite(path,"/",name,NULL); char *full_path = yon_char_unite(path,"/",name,NULL);
if (access(full_path,F_OK)){ if (access(full_path,F_OK)){
FILE *fl = fopen(full_path,"w"); FILE *fl = fopen(full_path,"w");
chmod(full_path,0777);
if (fl){ if (fl){
struct passwd *user = getpwnam(yon_ubl_root_user_get());
chown(path,user->pw_uid,user->pw_gid);
chmod(full_path,rules); chmod(full_path,rules);
fclose(fl); fclose(fl);
return 1; return 1;
@ -2260,22 +2277,34 @@ int yon_file_create(char *path, char *name, int rules){
int yon_file_create_full_path(char *path, int rules){ int yon_file_create_full_path(char *path, int rules){
if (path){ if (path){
if (access(path,F_OK)){ if (access(path,F_OK)){
FILE *fl = fopen(path,"w"); int size;
chmod(path,0777); config_str parsed = yon_char_parse(path,&size,"/");
if (fl){ char *current = "";
chmod(path,rules); for (int i=0;i<size;i++){
fclose(fl); char *temp = yon_char_unite(current,strcmp(current,"/")?"/":"",parsed[i],NULL);
return 1; if (!yon_char_is_empty(temp)){
if (access(temp,F_OK)){
if (i!=size-1){
mkdir(temp,0755);
} else { } else {
return 0; FILE *fl = fopen(temp,"w");
int chmod_success = chmod(temp,rules);
} }
} else { struct passwd *user = getpwnam(yon_ubl_root_user_get());
return -1; int chown_success = chown(temp,user->pw_uid,user->pw_gid);
} }
}
if (!yon_char_is_empty(current)) free(current);
current = temp;
}
return 1;
} else { } else {
return 0; return 0;
} }
} }
return 0;
}
config_str yon_file_list_dirs (char *path, int *size){ config_str yon_file_list_dirs (char *path, int *size){
(*size)=0; (*size)=0;

@ -432,6 +432,8 @@ char **yon_char_parsed_rip(char **char_string, int *size, int item_to_delete);
*/ */
int yon_char_parsed_check_exist(char **parameters, int size, char *param); int yon_char_parsed_check_exist(char **parameters, int size, char *param);
int yon_char_parsed_strstr(char **parameters, int size, char *param);
/**yon_char_parsed_check_repeats(char **parameters, int size) /**yon_char_parsed_check_repeats(char **parameters, int size)
* [EN] * [EN]
* Checks if [parameters] string array of length [size] * Checks if [parameters] string array of length [size]

Loading…
Cancel
Save