summaryrefslogtreecommitdiffstats
path: root/ctx.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2021-09-21 11:56:02 -0400
committerTavian Barnes <tavianator@tavianator.com>2021-09-21 11:56:02 -0400
commit5353347f23f4a0cb044d1d87d7747dedc71f525c (patch)
treeaed48680549c5f062f2f9bea8eae9ad5cb46fded /ctx.h
parent4bcb10a88e3d282494642c1fa10140b42f501e97 (diff)
downloadbfs-5353347f23f4a0cb044d1d87d7747dedc71f525c.tar.xz
ctx: Also deduplicate the standard streams
This fixes some potential missing output when the same file is used in a redirection and something like -fprint. The main benefit is smarter handling of /dev/stdout, which will now share the CFILE* with cout.
Diffstat (limited to 'ctx.h')
-rw-r--r--ctx.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/ctx.h b/ctx.h
index f089b84..02d296f 100644
--- a/ctx.h
+++ b/ctx.h
@@ -164,16 +164,19 @@ const struct bfs_groups *bfs_ctx_groups(const struct bfs_ctx *ctx);
const struct bfs_mtab *bfs_ctx_mtab(const struct bfs_ctx *ctx);
/**
- * Open a file for the bfs context.
+ * Deduplicate an opened file.
*
* @param ctx
* The bfs context.
- * @param use_color
- * Whether to use colors if the file is a TTY.
+ * @param cfile
+ * The opened file.
+ * @param path
+ * The path to the opened file (or NULL for standard streams).
* @return
- * The opened file, or NULL on failure.
+ * If the same file was opened previously, that file is returned. If cfile is a new file,
+ * cfile itself is returned. If an error occurs, NULL is returned.
*/
-struct CFILE *bfs_ctx_open(struct bfs_ctx *ctx, const char *path, bool use_color);
+struct CFILE *bfs_ctx_dedup(struct bfs_ctx *ctx, struct CFILE *cfile, const char *path);
/**
* Dump the parsed command line.