summaryrefslogtreecommitdiff
path: root/myfind/user_belong/user_belong.c
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /myfind/user_belong/user_belong.c
add: added projectsHEADmain
Diffstat (limited to 'myfind/user_belong/user_belong.c')
-rw-r--r--myfind/user_belong/user_belong.c25
1 files changed, 25 insertions, 0 deletions
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 <pwd.h>
+#include <stdio.h>
+#include <sys/stat.h>
+
+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;
+}