From 309c9a29e32edc07cb06e329669be7e30f8d9ed5 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 16 Sep 2015 12:25:53 -0400 Subject: bftw() interface improvements: - Use enums instead of ints where it makes sense - Move the file path inside struct BFTW - Expose a fd and relative path for *at() calls --- color.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'color.c') diff --git a/color.c b/color.c index 2928fe2..b67d6a4 100644 --- a/color.c +++ b/color.c @@ -282,18 +282,20 @@ static void print_esc(const char *esc, FILE *file) { fputs("m", file); } -void pretty_print(const color_table *colors, const char *fpath, const struct BFTW *ftwbuf) { +void pretty_print(const color_table *colors, const struct BFTW *ftwbuf) { + const char *path = ftwbuf->path; + if (!colors) { - puts(fpath); + puts(path); return; } - const char *filename = fpath + ftwbuf->base; + const char *filename = path + ftwbuf->nameoff; if (colors->dir) { print_esc(colors->dir, stdout); } - fwrite(fpath, 1, ftwbuf->base, stdout); + fwrite(path, 1, ftwbuf->nameoff, stdout); if (colors->dir) { print_esc(colors->reset, stdout); } @@ -309,7 +311,7 @@ void pretty_print(const color_table *colors, const char *fpath, const struct BFT fputs("\n", stdout); } -void print_error(const color_table *colors, const char *fpath, int error) { +void print_error(const color_table *colors, const char *path, int error) { const char *color = NULL; if (colors) { color = colors->orphan; @@ -318,7 +320,7 @@ void print_error(const color_table *colors, const char *fpath, int error) { if (color) { print_esc(color, stderr); } - fprintf(stderr, "Error at %s: %s\n", fpath, strerror(error)); + fprintf(stderr, "Error at %s: %s\n", path, strerror(error)); if (color) { print_esc(colors->reset, stderr); } -- cgit v1.2.3