diff options
-rw-r--r-- | src/output/sfrt_output_error.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/output/sfrt_output_error.c b/src/output/sfrt_output_error.c index 9e26f21..46b637b 100644 --- a/src/output/sfrt_output_error.c +++ b/src/output/sfrt_output_error.c @@ -2,7 +2,10 @@ #include <string.h> #include <errno.h> #include <unistd.h> + #include <sofort/sofort.h> +#include "sofort_driver_impl.h" +#include "sofort_dprintf_impl.h" static const char aclr_reset[] = "\x1b[0m"; static const char aclr_bold[] = "\x1b[1m"; @@ -75,19 +78,24 @@ static int sfrt_output_error_record_plain( { const char * epath; const char * errdesc = sfrt_output_strerror(erri); + int fderr = sfrt_driver_fderr(dctx); epath = erri->euctx ? *erri->euctx->path : erri->eunit; if (epath && !(erri->eflags & SFRT_ERROR_NESTED)) - if (fprintf(stderr,"%s: [%s] '%s':\n", + if (sfrt_dprintf( + fderr, + "%s: [%s] '%s':\n", dctx->program, sfrt_output_unit_header(erri), epath) < 0) return -1; - if (fprintf(stderr,"%s: %s %s(), line %d%s%s.\n", + if (sfrt_dprintf( + fderr, + "%s: %s %s(), line %d%s%s.\n", dctx->program, sfrt_output_error_header(erri), erri->efunction, @@ -96,7 +104,7 @@ static int sfrt_output_error_record_plain( errdesc) < 0) return -1; - return fflush(stderr); + return 0; } static int sfrt_output_error_record_annotated( @@ -105,14 +113,15 @@ static int sfrt_output_error_record_annotated( { const char * epath; const char * errdesc = sfrt_output_strerror(erri); + int fderr = sfrt_driver_fderr(dctx); epath = erri->euctx ? *erri->euctx->path : erri->eunit; if (epath && !(erri->eflags & SFRT_ERROR_NESTED)) - if (fprintf( - stderr, + if (sfrt_dprintf( + fderr, "%s%s%s:%s %s[%s]%s %s%s'%s'%s:\n", aclr_bold,aclr_magenta, @@ -128,8 +137,8 @@ static int sfrt_output_error_record_annotated( aclr_reset) < 0) return -1; - if (fprintf( - stderr, + if (sfrt_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 sfrt_output_error_record_annotated( aclr_reset) < 0) return -1; - return fflush(stderr); + return 0; } int sfrt_output_error_record( @@ -167,7 +176,7 @@ int sfrt_output_error_record( else if (dctx->cctx->drvflags & SFRT_DRIVER_ANNOTATE_ALWAYS) return sfrt_output_error_record_annotated(dctx,erri); - else if (isatty(STDERR_FILENO)) + else if (isatty(sfrt_driver_fderr(dctx))) return sfrt_output_error_record_annotated(dctx,erri); else @@ -204,7 +213,7 @@ int sfrt_output_error_vector(const struct sfrt_driver_ctx * dctx) else if (dctx->cctx->drvflags & SFRT_DRIVER_ANNOTATE_ALWAYS) return sfrt_output_error_vector_annotated(dctx); - else if (isatty(STDERR_FILENO)) + else if (isatty(sfrt_driver_fderr(dctx))) return sfrt_output_error_vector_annotated(dctx); else |