about summary refs log tree commit diff
path: root/lr.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-10-22 23:28:31 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2015-10-22 23:28:31 +0200
commit9d4a399a29f1eb97bb6495e09adc0c3168eb15d8 (patch)
treee7a75cf1f5664d870bfc0ccdac4374b694d1cd5f /lr.c
parent450a1f188374d6cebc97a13d759059297709ae26 (diff)
downloadlr-9d4a399a29f1eb97bb6495e09adc0c3168eb15d8.tar.gz
lr-9d4a399a29f1eb97bb6495e09adc0c3168eb15d8.tar.xz
lr-9d4a399a29f1eb97bb6495e09adc0c3168eb15d8.zip
add %u %U %g %G
Diffstat (limited to 'lr.c')
-rw-r--r--lr.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/lr.c b/lr.c
index 50c0ca5..aab2d90 100644
--- a/lr.c
+++ b/lr.c
@@ -24,6 +24,8 @@ TODO:
 #include <dirent.h>
 #include <errno.h>
 #include <fnmatch.h>
+#include <grp.h>
+#include <pwd.h>
 #include <search.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -598,6 +600,33 @@ print(const void *nodep, const VISIT which, const int depth)
 					printf("%s", buf);
 					break;
 					}
+
+				case 'g':
+					{
+						struct group *g = getgrgid(fi->sb.st_gid);
+						if (g) {
+							printf("%*s", -gwid, g->gr_name);
+							break;
+						}
+						/* FALLTHRU */
+					}
+				case 'G':
+					printf("%*ld", gwid, fi->sb.st_gid);
+					break;
+
+				case 'u':
+					{
+						struct passwd *p = getpwuid(fi->sb.st_uid);
+						if (p) {
+							printf("%*s", -uwid, p->pw_name);
+							break;
+						}
+						/* FALLTHRU */
+					}
+				case 'U':
+					printf("%*ld", uwid, fi->sb.st_uid);
+					break;
+
 				default:
 					putchar('%');
 					putchar(*s);