diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2020-09-28 09:08:56 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2020-09-28 09:08:56 -0400 |
commit | ffda15423b9920377c8af97e208f9d78b5c80d91 (patch) | |
tree | 58b776cb6fa82add159aaa22d737a08ebbdd3c9b /ctx.c | |
parent | 62bbbe1a4165f63b31c68b1595ecb0e67d7af3dc (diff) | |
download | bfs-ffda15423b9920377c8af97e208f9d78b5c80d91.tar.xz |
ctx: Perserve errno better in bfs_ctx_open()
Diffstat (limited to 'ctx.c')
-rw-r--r-- | ctx.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -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; } |