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;
}
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){
if (parameters){
*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){
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){
fputs(text,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);
if (access(full_path,F_OK)){
FILE *fl = fopen(full_path,"w");
chmod(full_path,0777);
if (fl){
struct passwd *user = getpwnam(yon_ubl_root_user_get());
chown(path,user->pw_uid,user->pw_gid);
chmod(full_path,rules);
fclose(fl);
return 1;
@ -2260,21 +2277,33 @@ int yon_file_create(char *path, char *name, int rules){
int yon_file_create_full_path(char *path, int rules){
if (path){
if (access(path,F_OK)){
FILE *fl = fopen(path,"w");
chmod(path,0777);
if (fl){
chmod(path,rules);
fclose(fl);
return 1;
} else {
return 0;
int size;
config_str parsed = yon_char_parse(path,&size,"/");
char *current = "";
for (int i=0;i<size;i++){
char *temp = yon_char_unite(current,strcmp(current,"/")?"/":"",parsed[i],NULL);
if (!yon_char_is_empty(temp)){
if (access(temp,F_OK)){
if (i!=size-1){
mkdir(temp,0755);
} else {
FILE *fl = fopen(temp,"w");
int chmod_success = chmod(temp,rules);
}
struct passwd *user = getpwnam(yon_ubl_root_user_get());
int chown_success = chown(temp,user->pw_uid,user->pw_gid);
}
}
if (!yon_char_is_empty(current)) free(current);
current = temp;
}
return 1;
} else {
return -1;
return 0;
}
} else {
return 0;
}
return 0;
}
config_str yon_file_list_dirs (char *path, int *size){

@ -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_strstr(char **parameters, int size, char *param);
/**yon_char_parsed_check_repeats(char **parameters, int size)
* [EN]
* Checks if [parameters] string array of length [size]

Loading…
Cancel
Save