diff options
author | midipix <writeonce@midipix.org> | 2018-08-05 00:53:56 -0400 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2018-08-05 03:22:21 -0400 |
commit | 5eaec44974e5414dafcda39c005adcbb6bd752f3 (patch) | |
tree | a50b8ef486fa0e3630464b313ebdbdec4a32f033 /src | |
parent | b8225b67f6e452b4751150e52b3dfee54744f4bf (diff) | |
download | apimagic-5eaec44974e5414dafcda39c005adcbb6bd752f3.tar.bz2 apimagic-5eaec44974e5414dafcda39c005adcbb6bd752f3.tar.xz |
amgc_output_error_record(): re-implemented with fdctx and pure fdio.
Diffstat (limited to 'src')
-rw-r--r-- | src/output/amgc_output_error.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/output/amgc_output_error.c b/src/output/amgc_output_error.c index 041fc11..f76d068 100644 --- a/src/output/amgc_output_error.c +++ b/src/output/amgc_output_error.c @@ -2,7 +2,10 @@ #include <string.h> #include <errno.h> #include <unistd.h> + #include <apimagic/apimagic.h> +#include "apimagic_driver_impl.h" +#include "apimagic_dprintf_impl.h" static const char aclr_reset[] = "\x1b[0m"; static const char aclr_bold[] = "\x1b[1m"; @@ -75,19 +78,24 @@ static int amgc_output_error_record_plain( { const char * epath; const char * errdesc = amgc_output_strerror(erri); + int fderr = amgc_driver_fderr(dctx); epath = erri->euctx ? *erri->euctx->path : erri->eunit; if (epath && !(erri->eflags & AMGC_ERROR_NESTED)) - if (fprintf(stderr,"%s: [%s] '%s':\n", + if (amgc_dprintf( + fderr, + "%s: [%s] '%s':\n", dctx->program, amgc_output_unit_header(erri), epath) < 0) return -1; - if (fprintf(stderr,"%s: %s %s(), line %d%s%s.\n", + if (amgc_dprintf( + fderr, + "%s: %s %s(), line %d%s%s.\n", dctx->program, amgc_output_error_header(erri), erri->efunction, @@ -96,7 +104,7 @@ static int amgc_output_error_record_plain( errdesc) < 0) return -1; - return fflush(stderr); + return 0; } static int amgc_output_error_record_annotated( @@ -105,14 +113,15 @@ static int amgc_output_error_record_annotated( { const char * epath; const char * errdesc = amgc_output_strerror(erri); + int fderr = amgc_driver_fderr(dctx); epath = erri->euctx ? *erri->euctx->path : erri->eunit; if (epath && !(erri->eflags & AMGC_ERROR_NESTED)) - if (fprintf( - stderr, + if (amgc_dprintf( + fderr, "%s%s%s:%s %s[%s]%s %s%s'%s'%s:\n", aclr_bold,aclr_magenta, @@ -128,8 +137,8 @@ static int amgc_output_error_record_annotated( aclr_reset) < 0) return -1; - if (fprintf( - stderr, + if (amgc_dprintf( + fderr, "%s%s%s:%s %s%s%s %s%s%s()%s, %s%sline %d%s%s%s%s%s.\n", aclr_bold,aclr_magenta, @@ -154,7 +163,7 @@ static int amgc_output_error_record_annotated( aclr_reset) < 0) return -1; - return fflush(stderr); + return 0; } int amgc_output_error_record( @@ -167,7 +176,7 @@ int amgc_output_error_record( else if (dctx->cctx->drvflags & AMGC_DRIVER_ANNOTATE_ALWAYS) return amgc_output_error_record_annotated(dctx,erri); - else if (isatty(STDERR_FILENO)) + else if (isatty(amgc_driver_fderr(dctx))) return amgc_output_error_record_annotated(dctx,erri); else @@ -204,7 +213,7 @@ int amgc_output_error_vector(const struct amgc_driver_ctx * dctx) else if (dctx->cctx->drvflags & AMGC_DRIVER_ANNOTATE_ALWAYS) return amgc_output_error_vector_annotated(dctx); - else if (isatty(STDERR_FILENO)) + else if (isatty(amgc_driver_fderr(dctx))) return amgc_output_error_vector_annotated(dctx); else |