summaryrefslogtreecommitdiffstats
path: root/ctx.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-09-28 09:08:56 -0400
committerTavian Barnes <tavianator@tavianator.com>2020-09-28 09:08:56 -0400
commitffda15423b9920377c8af97e208f9d78b5c80d91 (patch)
tree58b776cb6fa82add159aaa22d737a08ebbdd3c9b /ctx.c
parent62bbbe1a4165f63b31c68b1595ecb0e67d7af3dc (diff)
downloadbfs-ffda15423b9920377c8af97e208f9d78b5c80d91.tar.xz
ctx: Perserve errno better in bfs_ctx_open()
Diffstat (limited to 'ctx.c')
-rw-r--r--ctx.c7
1 files changed, 7 insertions, 0 deletions
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;
}