summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-02-05 14:11:38 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-02-06 15:22:39 -0500
commit3b82c88d1950291b1b703f082df43ec1b9654eb5 (patch)
treea438d7bf0a0c969265fdb7a71bf711c98b7f77d0 /src
parent89ecb2a08467cd8aa6ba70f8519df494652cac96 (diff)
downloadbfs-3b82c88d1950291b1b703f082df43ec1b9654eb5.tar.xz
color: New API to check if stat() is necessary
Diffstat (limited to 'src')
-rw-r--r--src/color.c5
-rw-r--r--src/color.h12
2 files changed, 11 insertions, 6 deletions
diff --git a/src/color.c b/src/color.c
index 1f10c04..8c32a68 100644
--- a/src/color.c
+++ b/src/color.c
@@ -764,6 +764,11 @@ static bool is_link_broken(const struct BFTW *ftwbuf) {
}
}
+bool colors_need_stat(const struct colors *colors) {
+ return colors->setuid || colors->setgid || colors->executable || colors->multi_hard
+ || colors->sticky_other_writable || colors->other_writable || colors->sticky;
+}
+
/** Get the color for a file. */
static const struct esc_seq *file_color(const struct colors *colors, const char *filename, const struct BFTW *ftwbuf, enum bfs_stat_flags flags) {
enum bfs_type type = bftw_type(ftwbuf, flags);
diff --git a/src/color.h b/src/color.h
index 760aa9d..85633a4 100644
--- a/src/color.h
+++ b/src/color.h
@@ -19,17 +19,17 @@
struct colors;
/**
- * Parse a color table.
- *
- * @return The parsed color table.
+ * Parse the color table from the environment.
*/
struct colors *parse_colors(void);
/**
+ * Check if stat() info is required to color a file correctly.
+ */
+bool colors_need_stat(const struct colors *colors);
+
+/**
* Free a color table.
- *
- * @param colors
- * The color table to free.
*/
void free_colors(struct colors *colors);