Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- typedef enum {
- READ, WRITE, DEL, RENAME, COPY
- } PermsE;
- void setPerm(uint8_t *perms, PermsE permNr) {
- *perms |= (1 << permNr);
- }
- void resetPerm(uint8_t *perms, PermsE permNr) {
- *perms &= ~(1 << permNr);
- }
- int hasPerm(uint8_t perms, PermsE permNr) {
- return 1 & (perms >> permNr);
- }
- void printPerms(uint8_t perms) {
- for (int i = 0; i < 5; i++) {
- if (!hasPerm(perms, i)) {
- printf("-/");
- continue;
- }
- switch(i) {
- case READ:
- printf("Read");
- break;
- case WRITE:
- printf("Write");
- break;
- case DEL:
- printf("Delete");
- break;
- case RENAME:
- printf("Rename");
- break;
- case COPY:
- printf("Copy");
- break;
- }
- putchar('/');
- }
- puts("");
- }
- int main(void) {
- uint8_t perms = 0;
- setPerm(&perms, WRITE);
- setPerm(&perms, RENAME);
- setPerm(&perms, DEL);
- printPerms(perms);
- resetPerm(&perms, WRITE);
- setPerm(&perms, READ);
- printPerms(perms);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement