summaryrefslogtreecommitdiff
path: root/myfind/group_belong
diff options
context:
space:
mode:
Diffstat (limited to 'myfind/group_belong')
-rw-r--r--myfind/group_belong/Makefile17
-rw-r--r--myfind/group_belong/group_belong.c25
2 files changed, 42 insertions, 0 deletions
diff --git a/myfind/group_belong/Makefile b/myfind/group_belong/Makefile
new file mode 100644
index 0000000..b5672f4
--- /dev/null
+++ b/myfind/group_belong/Makefile
@@ -0,0 +1,17 @@
+CC = gcc CFLAGS = -std = c99 - pedantic - Werror - Wall - Wextra
+ - Wvla
+
+ SRC = group_belong.c OBJ = $(SRC
+ :.c =.o)
+
+ all
+ : $(OBJ) $(CC)
+ - o group_belong $(OBJ)
+
+ $(OBJ)
+ : $(SRC)
+
+ .PHONY
+ : clean
+
+ clean : $(RM) $(OBJ) group_belong
diff --git a/myfind/group_belong/group_belong.c b/myfind/group_belong/group_belong.c
new file mode 100644
index 0000000..20302d5
--- /dev/null
+++ b/myfind/group_belong/group_belong.c
@@ -0,0 +1,25 @@
+#include <grp.h>
+#include <stdio.h>
+#include <sys/stat.h>
+
+int main(int argc, char **argv)
+{
+ if (argc != 3)
+ return 2;
+
+ struct group *g = getgrnam(argv[2]);
+ if (!g)
+ {
+ printf("group %s does not exist\n", argv[2]);
+ return 0;
+ }
+ struct stat s;
+ stat(argv[1], &s);
+
+ printf("%s does ", argv[1]);
+ if (s.st_gid != g->gr_gid)
+ printf("not ");
+ printf("belong to group %s\n", argv[2]);
+
+ return 0;
+}