diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /myfind/display_perm | |
Diffstat (limited to 'myfind/display_perm')
| -rw-r--r-- | myfind/display_perm/Makefile | 15 | ||||
| -rw-r--r-- | myfind/display_perm/display_perm.c | 25 |
2 files changed, 40 insertions, 0 deletions
diff --git a/myfind/display_perm/Makefile b/myfind/display_perm/Makefile new file mode 100644 index 0000000..4caed42 --- /dev/null +++ b/myfind/display_perm/Makefile @@ -0,0 +1,15 @@ +CC = gcc +CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla + +SRC = display_perm.c +OBJ = $(SRC:.c=.o) + +all: $(OBJ) + $(CC) -o display_perm $(OBJ) + +$(OBJ): $(SRC) + +.PHONY: clean + +clean : + $(RM) $(OBJ) display_perm diff --git a/myfind/display_perm/display_perm.c b/myfind/display_perm/display_perm.c new file mode 100644 index 0000000..3ad17e6 --- /dev/null +++ b/myfind/display_perm/display_perm.c @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <sys/stat.h> + +int main(int argc, char **argv) +{ + if (argc != 2) + return 2; + + struct stat s; + stat(argv[1], &s); + + // User + printf("%d", + ((s.st_mode & S_IRUSR) != 0) * 4 + ((s.st_mode & S_IWUSR) != 0) * 2 + + ((s.st_mode & S_IXUSR) != 0)); + printf("%d", + ((s.st_mode & S_IRGRP) != 0) * 4 + ((s.st_mode & S_IWGRP) != 0) * 2 + + ((s.st_mode & S_IXGRP) != 0)); + printf("%d", + ((s.st_mode & S_IROTH) != 0) * 4 + ((s.st_mode & S_IWOTH) != 0) * 2 + + ((s.st_mode & S_IXOTH) != 0)); + printf("\n"); + + return 0; +} |
