diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2021-09-26 15:23:26 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2021-09-26 15:23:26 -0400 |
commit | 78944c815a5d8d1c93771ca1c343b9406bc262c4 (patch) | |
tree | 0e11144b526a3a1cebeedf4f7277b60d40488580 /color.c | |
parent | 2e918d33be152c1a57ffb3ff53e344cafb161a8c (diff) | |
download | bfs-78944c815a5d8d1c93771ca1c343b9406bc262c4.tar.xz |
Don't truncate files until we know they're not duplicates
Diffstat (limited to 'color.c')
-rw-r--r-- | color.c | 39 |
1 files changed, 2 insertions, 37 deletions
@@ -501,7 +501,7 @@ void free_colors(struct colors *colors) { } } -static CFILE *cfalloc(void) { +CFILE *cfwrap(FILE *file, const struct colors *colors, bool close) { CFILE *cfile = malloc(sizeof(*cfile)); if (!cfile) { return NULL; @@ -513,43 +513,8 @@ static CFILE *cfalloc(void) { return NULL; } - cfile->file = NULL; - cfile->colors = NULL; - cfile->close = false; - - return cfile; -} - -CFILE *cfopen(const char *path, const struct colors *colors) { - CFILE *cfile = cfalloc(); - if (!cfile) { - return NULL; - } - - cfile->file = xfopen(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC); - if (!cfile->file) { - cfclose(cfile); - return NULL; - } - cfile->close = true; - - if (isatty(fileno(cfile->file))) { - cfile->colors = colors; - } else { - cfile->colors = NULL; - } - - return cfile; -} - -CFILE *cfdup(FILE *file, const struct colors *colors) { - CFILE *cfile = cfalloc(); - if (!cfile) { - return NULL; - } - - cfile->close = false; cfile->file = file; + cfile->close = close; if (isatty(fileno(file))) { cfile->colors = colors; |