From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- myfind/user_belong/Makefile | 17 +++++++++++++++++ myfind/user_belong/user_belong.c | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 myfind/user_belong/Makefile create mode 100644 myfind/user_belong/user_belong.c (limited to 'myfind/user_belong') diff --git a/myfind/user_belong/Makefile b/myfind/user_belong/Makefile new file mode 100644 index 0000000..ca37a55 --- /dev/null +++ b/myfind/user_belong/Makefile @@ -0,0 +1,17 @@ +CC = gcc CFLAGS = -std = c99 - pedantic - Werror - Wall - Wextra + - Wvla + + SRC = user_belong.c OBJ = $(SRC + :.c =.o) + + all + : $(OBJ) $(CC) + - o user_belong $(OBJ) + + $(OBJ) + : $(SRC) + + .PHONY + : clean + + clean : $(RM) $(OBJ) user_belong diff --git a/myfind/user_belong/user_belong.c b/myfind/user_belong/user_belong.c new file mode 100644 index 0000000..bb7332a --- /dev/null +++ b/myfind/user_belong/user_belong.c @@ -0,0 +1,25 @@ +#include +#include +#include + +int main(int argc, char **argv) +{ + if (argc != 3) + return 2; + + struct passwd *p = getpwnam(argv[2]); + if (!p) + { + printf("user %s does not exist\n", argv[2]); + return 0; + } + struct stat s; + stat(argv[1], &s); + + printf("%s does ", argv[1]); + if (s.st_uid != p->pw_uid) + printf("not "); + printf("belong to user %s\n", argv[2]); + + return 0; +} -- cgit v1.2.3