summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-02-24 09:32:01 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-02-24 14:35:02 -0500
commite5543a849302e9ce3d5e83693283736c6a26a86c (patch)
treecad539763475fc929cb16f5b8c7bdbd391c5dd7f
parent851459e9f16921c06604a0fb090856724933f378 (diff)
downloadbfs-e5543a849302e9ce3d5e83693283736c6a26a86c.tar.xz
Color broken symlinks correctly.
-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);
}