This commit is contained in:
Your Name 2023-11-02 12:08:06 +03:00
parent 44f7c3a669
commit ae4f4e73ed

View File

@ -20,7 +20,59 @@ mode_t mu_parse_mode(const char *s) {
if (!*p && mode < 07777U)
return mode;
return -1;
mode = 0;
/* 0 - + */
int type = 0;
mode_t mask = 0;
for (size_t i = 0; i < strlen(s); i++) {
switch (s[i]) {
case 'r':
mode |= A(RD_PERM);
break;
case 'w':
mode |= A(WR_PERM);
break;
case 'x':
mode |= A(EX_PERM);
break;
case '+':
type = 0;
break;
case '-':
type = 1;
break;
case 'g':
mask |= G(FULL_PERM);
break;
case 'u':
mask |= U(FULL_PERM);
break;
case 'o':
mask |= O(FULL_PERM);
break;
case 'a':
mask |= A(FULL_PERM);
break;
default:
return -1;
}
}
if (type)
return ~mask & mode;
return mask & mode;
}
#endif