static void set_perm_string(FileView *view, const int *perms, const int *origin_perms) { int i = 0; char *add_perm[] = {"u+r", "u+w", "u+x", "u+s", "g+r", "g+w", "g+x", "g+s", "o+r", "o+w", "o+x", "o+t"}; char *sub_perm[] = {"u-r", "u-w", "u-x", "u-s", "g-r", "g-w", "g-x", "g-s", "o-r", "o-w", "o-x", "o-t"}; char *add_adv_perm[] = {"u-x+X", "g-x+X", "o-x+X"}; char perm_str[64] = " "; size_t perm_str_len = strlen(perm_str); if(adv_perms[0] && adv_perms[1] && adv_perms[2]) { adv_perms[0] = -1; adv_perms[1] = -1; adv_perms[2] = -1; } perm_str_len += snprintf(perm_str + perm_str_len, sizeof(perm_str) - perm_str_len, "a-x+X,"); for(i = 0; i < 12; i++) { const char *perm; if(perms[i] == -1) continue; if(perms[i] == origin_perms[i] && !perms[12]) { if((i != 2 && i != 6 && i != 10) || !adv_perms[i/4]) continue; } if((i == 2 || i == 6 || i == 10) && adv_perms[i/4] < 0) continue; if(!perms[i]) { perm = sub_perm[i]; } else if((i == 2 || i == 6 || i == 10) && adv_perms[i/4]) { perm = add_adv_perm[i/4]; } else { perm = add_perm[i]; } perm_str_len += snprintf(perm_str + perm_str_len, sizeof(perm_str) - perm_str_len, "%s,", perm); } perm_str[strlen(perm_str) - 1] = '\0'; /* Remove last comma (','). */ files_chmod(view, perm_str, perms[12]); }
static void set_perm_string(FileView *view, const int *perms, const int *origin_perms) { int i = 0; char *add_perm[] = {"u+r", "u+w", "u+x", "u+s", "g+r", "g+w", "g+x", "g+s", "o+r", "o+w", "o+x", "o+t"}; char *sub_perm[] = {"u-r", "u-w", "u-x", "u-s", "g-r", "g-w", "g-x", "g-s", "o-r", "o-w", "o-x", "o-t"}; char *add_adv_perm[] = {"u-x+X", "g-x+X", "o-x+X"}; char perm_string[64] = " "; if(adv_perms[0] && adv_perms[1] && adv_perms[2]) { adv_perms[0] = -1; adv_perms[1] = -1; adv_perms[2] = -1; } strcat(perm_string, "a-x+X,"); for(i = 0; i < 12; i++) { if(perms[i] == -1) continue; if(perms[i] == origin_perms[i] && !perms[12]) { if((i != 2 && i != 6 && i != 10) || !adv_perms[i/4]) continue; } if((i == 2 || i == 6 || i == 10) && adv_perms[i/4] < 0) continue; if(perms[i]) { if((i == 2 || i == 6 || i == 10) && adv_perms[i/4]) strcat(perm_string, add_adv_perm[i/4]); else strcat(perm_string, add_perm[i]); } else { strcat(perm_string, sub_perm[i]); } strcat(perm_string, ","); } perm_string[strlen(perm_string) - 1] = '\0'; /* Remove last , */ files_chmod(view, perm_string, perms[12]); }