From 212cc3329fb37b02867a0efc33dc9ae6e8b731c2 Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 3 May 2020 16:27:46 +0000 Subject: kiss: use our own version of stat for portability purposes. FossilOrigin-Name: 44c082a4672f3de9f932cd7262e2d8b4cba2fc590750db9b1fefc38673910045 --- bin/kiss-stat.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 bin/kiss-stat.c (limited to 'bin') 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 +#include +#include + +int main (int argc, char *argv[]) { + struct stat sb; + + // Exit if no or multiple arguments are given + if (argc != 2) { + fprintf(stderr, "Usage: %s \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); +} -- cgit v1.2.3