From 5353347f23f4a0cb044d1d87d7747dedc71f525c Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 21 Sep 2021 11:56:02 -0400 Subject: 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. --- ctx.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'ctx.h') 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. -- cgit v1.2.3