summaryrefslogtreecommitdiffstats
path: root/color.c
diff options
context:
space:
mode:
Diffstat (limited to 'color.c')
-rw-r--r--color.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/color.c b/color.c
index 18a975f..640cd7e 100644
--- a/color.c
+++ b/color.c
@@ -11,6 +11,7 @@
#include "color.h"
#include "bftw.h"
+#include "util.h"
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
@@ -413,6 +414,32 @@ static int print_path(CFILE *cfile, const struct BFTW *ftwbuf) {
return 0;
}
+static int print_link(CFILE *cfile, const struct BFTW *ftwbuf) {
+ int ret = -1;
+
+ char *target = xreadlinkat(ftwbuf->at_fd, ftwbuf->at_path, 0);
+ if (!target) {
+ goto done;
+ }
+
+ struct BFTW altbuf = *ftwbuf;
+ altbuf.path = target;
+ altbuf.nameoff = xbasename(target) - target;
+
+ struct stat statbuf;
+ if (fstatat(ftwbuf->at_fd, ftwbuf->at_path, &statbuf, 0) == 0) {
+ altbuf.statbuf = &statbuf;
+ } else {
+ altbuf.statbuf = NULL;
+ }
+
+ ret = print_path(cfile, &altbuf);
+
+done:
+ free(target);
+ return ret;
+}
+
int cfprintf(CFILE *cfile, const char *format, ...) {
const struct colors *colors = cfile->colors;
FILE *file = cfile->file;
@@ -449,6 +476,12 @@ int cfprintf(CFILE *cfile, const char *format, ...) {
}
break;
+ case 'L':
+ if (print_link(cfile, va_arg(args, const struct BFTW *)) != 0) {
+ goto done;
+ }
+ break;
+
case '{':
memcpy(name, i + 1, 2);
esc = get_color(colors, name);