From ffda15423b9920377c8af97e208f9d78b5c80d91 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 28 Sep 2020 09:08:56 -0400 Subject: ctx: Perserve errno better in bfs_ctx_open() --- ctx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ctx.c b/ctx.c index 95e668c..cf47bc4 100644 --- a/ctx.c +++ b/ctx.c @@ -121,13 +121,17 @@ struct bfs_ctx_file { }; CFILE *bfs_ctx_open(struct bfs_ctx *ctx, const char *path, bool use_color) { + int error = 0; + CFILE *cfile = cfopen(path, use_color ? ctx->colors : NULL); if (!cfile) { + error = errno; goto out; } struct bfs_stat sb; if (bfs_stat(fileno(cfile->file), NULL, 0, &sb) != 0) { + error = errno; goto out_close; } @@ -136,6 +140,7 @@ CFILE *bfs_ctx_open(struct bfs_ctx *ctx, const char *path, bool use_color) { struct trie_leaf *leaf = trie_insert_mem(&ctx->files, id, sizeof(id)); if (!leaf) { + error = errno; goto out_close; } @@ -148,6 +153,7 @@ CFILE *bfs_ctx_open(struct bfs_ctx *ctx, const char *path, bool use_color) { struct bfs_ctx_file *ctx_file = malloc(sizeof(*ctx_file)); if (!ctx_file) { + error = errno; trie_remove(&ctx->files, leaf); goto out_close; } @@ -163,6 +169,7 @@ out_close: cfclose(cfile); cfile = NULL; out: + errno = error; return cfile; } -- cgit v1.2.3