From: Ralph Corderoy Date: Mon, 29 May 2017 11:23:38 +0000 (+0100) Subject: uip/scansbr.c: Add PUTC() macro, similar to FPUTS(). X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/3395ff90fe5c311285e15357d06fb08938b9b849?ds=sidebyside uip/scansbr.c: Add PUTC() macro, similar to FPUTS(). FPUTS() exists, but all the putc(3) checks for error were written alongside in longhand. May as well have a PUTC() to match, though perhaps just the existing check of the FILE's sticky error state with ferror(3) is sufficient and neither macro is required. --- diff --git a/uip/scansbr.c b/uip/scansbr.c index a62faf2e..df9ef645 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -26,6 +26,10 @@ static m_getfld_state_t gstate; /* for accessor functions below */ #define DIEWRERR() adios (scnmsg, "write error on") +#define PUTC(c) \ + if (putc((c), scnout) == EOF) \ + DIEWRERR(); + #define FPUTS(buf) {\ if (fputs(buf,scnout) == EOF)\ DIEWRERR();\ @@ -169,7 +173,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, compnum++; if (scnout) { FPUTS (name); - if ( putc (':', scnout) == EOF) DIEWRERR(); + PUTC(':'); FPUTS (tmpbuf); } /* @@ -218,7 +222,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, goto finished; } if (scnout) { - if (putc ('\n', scnout) == EOF) DIEWRERR(); + PUTC('\n'); FPUTS (tmpbuf); } /* @@ -264,7 +268,7 @@ body:; if (scnout) { FPUTS ("\n\nBAD MSG:\n"); FPUTS (name); - if (putc ('\n', scnout) == EOF) DIEWRERR(); + PUTC('\n'); state = BODY; goto body; }