summaryrefslogtreecommitdiffstats
path: root/color.c
diff options
context:
space:
mode:
Diffstat (limited to 'color.c')
-rw-r--r--color.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/color.c b/color.c
index 7e76853..78d6e99 100644
--- a/color.c
+++ b/color.c
@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <unistd.h>
struct ext_color {
const char *ext;
@@ -210,7 +211,8 @@ done:
return colors;
}
-static const char *file_color(const struct colors *colors, const char *filename, const struct stat *sb) {
+static const char *file_color(const struct colors *colors, const char *filename, const struct BFTW *ftwbuf) {
+ const struct stat *sb = ftwbuf->statbuf;
if (!sb) {
return colors->orphan;
}
@@ -262,8 +264,13 @@ static const char *file_color(const struct colors *colors, const char *filename,
break;
case S_IFLNK:
- color = colors->link;
+ if (faccessat(ftwbuf->at_fd, ftwbuf->at_path, F_OK, 0) == 0) {
+ color = colors->link;
+ } else {
+ color = colors->orphan;
+ }
break;
+
case S_IFBLK:
color = colors->block;
break;
@@ -309,7 +316,7 @@ void pretty_print(const struct colors *colors, const struct BFTW *ftwbuf) {
print_esc(colors->reset, stdout);
}
- const char *color = file_color(colors, filename, ftwbuf->statbuf);
+ const char *color = file_color(colors, filename, ftwbuf);
if (color) {
print_esc(color, stdout);
}