From 7cd8bca5bbc93ed1352e02089d03c34a23609444 Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 23 Nov 2015 15:35:04 -0500 Subject: pretty printer: use common prolog/epilog for output stream selection. --- src/internal/perk_output.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/internal/perk_output.h (limited to 'src/internal') diff --git a/src/internal/perk_output.h b/src/internal/perk_output.h new file mode 100644 index 0000000..d60d78d --- /dev/null +++ b/src/internal/perk_output.h @@ -0,0 +1,31 @@ +#include + +static inline FILE * pe_output_prolog(const struct pe_common_ctx * cctx, FILE * fout, FILE ** ftmp) +{ + int fdout; + + *ftmp = (FILE *)0; + + if (fout) + return fout; + else if (!cctx) + return 0; + else if (cctx->fdout < 0) + return stdout; + + if ((fdout = dup(cctx->fdout)) < 0) + return 0; + + if ((*ftmp = fdopen(fdout,"a"))) + return *ftmp; + + close(fdout); + return 0; +} + +static inline int pe_output_epilog(int ret, FILE * f) +{ + if (f) + fclose(f); + return ret; +} -- cgit v1.2.3