This repository has been archived on 2026-07-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
cmc/3sem/cnts/contest5/03.c
T
2025-04-13 21:48:15 +03:00

37 lines
557 B
C
Executable File

#include <stdlib.h>
enum
{
RWX_PERMISSIONS = 0777,
};
int
parse_rwx_permissions(const char *str)
{
if (str == NULL) {
return -1;
}
const char expected[] = "rwxrwxrwx";
unsigned res = 0;
int i = 0;
while (str[i]) {
res <<= 1;
if (str[i] == expected[i] && expected[i]) {
res |= 1;
} else if (str[i] != '-' || !expected[i]) {
return -1;
}
++i;
}
if (res > RWX_PERMISSIONS || res < 0 || expected[i]) {
return -1;
}
return res;
}