aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-05-03 16:27:46 +0000
committermerakor <cem@ckyln.com>2020-05-03 16:27:46 +0000
commit212cc3329fb37b02867a0efc33dc9ae6e8b731c2 (patch)
tree8a1f13cce6aa795444ea4331751f4fa87884d8ee /bin
parent08a64b4ed7409014e848fde529905b906f86b3cd (diff)
downloadcpt-212cc3329fb37b02867a0efc33dc9ae6e8b731c2.tar.gz
kiss: use our own version of stat for portability purposes.
FossilOrigin-Name: 44c082a4672f3de9f932cd7262e2d8b4cba2fc590750db9b1fefc38673910045
Diffstat (limited to 'bin')
-rw-r--r--bin/kiss-stat.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/bin/kiss-stat.c b/bin/kiss-stat.c
new file mode 100644
index 0000000..d03bd13
--- /dev/null
+++ b/bin/kiss-stat.c
@@ -0,0 +1,32 @@
+// kiss-stat --- a utility for getting the user name of file owner
+// See LICENSE for copyright information
+
+/* The reason this simple tool exists is because 'stat' is not
+ * portable and ls is not exactly stable enough for scripting.
+ * This program is for outputting the owner name, and that's it.
+ */
+
+#include <pwd.h>
+#include <sys/stat.h>
+#include <stdio.h>
+
+int main (int argc, char *argv[]) {
+ struct stat sb;
+
+ // Exit if no or multiple arguments are given
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
+ return(1);
+ }
+
+ // Exit if file stat cannot be obtained
+ if (lstat(argv[1], &sb) == -1) {
+ perror(argv[0]);
+ return(1);
+ }
+
+ // Print the user name of file owner
+ struct passwd *pw = getpwuid(sb.st_uid);
+ printf("%s\n", pw->pw_name);
+ return(0);
+}