diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-02-24 09:32:01 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-02-24 14:35:02 -0500 |
commit | e5543a849302e9ce3d5e83693283736c6a26a86c (patch) | |
tree | cad539763475fc929cb16f5b8c7bdbd391c5dd7f /color.c | |
parent | 851459e9f16921c06604a0fb090856724933f378 (diff) | |
download | bfs-e5543a849302e9ce3d5e83693283736c6a26a86c.tar.xz |
Color broken symlinks correctly.
Diffstat (limited to 'color.c')
-rw-r--r-- | color.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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); } |