X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fscansbr.c;h=be68bf89162fb5c7c53ee761adaa7d8f10bcc623;hp=44cbf0d422896030c28d1fe5b859707c2394ea5f;hb=cafee7a804b8aa53166065e988ec0fc387862fc8;hpb=1691e80890e5d8ba258c51c214a3e91880e1db2b diff --git a/uip/scansbr.c b/uip/scansbr.c index 44cbf0d..be68bf8 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -3,13 +3,17 @@ * scansbr.c -- routines to help scan along... * * $Id$ + * + * This code is Copyright (c) 2002, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. */ #include #include #include #include -#include +#include #ifdef _FSTDIO # define _ptr _p /* Gag */ @@ -50,9 +54,11 @@ static int dat[5]; /* aux. data for format routine */ char *scanl = 0; /* text of most recent scanline */ +#define DIEWRERR() adios (scnmsg, "write error on") + #define FPUTS(buf) {\ if (mh_fputs(buf,scnout) == EOF)\ - adios (scnmsg, "write error on");\ + DIEWRERR();\ } /* @@ -187,7 +193,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, compnum++; if (outnum) { FPUTS (name); - putc (':', scnout); + if ( putc (':', scnout) == EOF) DIEWRERR(); FPUTS (tmpbuf); } /* @@ -228,7 +234,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, state = FILEEOF; /* stop now if scan cmd */ goto finished; } - putc ('\n', scnout); + if (putc ('\n', scnout) == EOF) DIEWRERR(); FPUTS (tmpbuf); /* * performance hack: some people like to run "inc" on @@ -249,7 +255,7 @@ body:; if (scnout->_cnt <= 0) { #endif if (fflush(scnout) == EOF) - adios (scnmsg, "write error on"); + DIEWRERR (); } #ifdef LINUX_STDIO state = m_getfld(state, name, scnout->_IO_write_ptr, @@ -274,7 +280,7 @@ body:; if (outnum) { FPUTS ("\n\nBAD MSG:\n"); FPUTS (name); - putc ('\n', scnout); + if (putc ('\n', scnout) == EOF) DIEWRERR(); state = BODY; goto body; } @@ -306,7 +312,10 @@ finished: if (size) dat[2] = size; else if (outnum > 0) + { dat[2] = ftell(scnout); + if (dat[2] == EOF) DIEWRERR(); + } if ((datecomp && !datecomp->c_text) || (!size && !outnum)) { struct stat st; @@ -322,9 +331,9 @@ finished: if (datecomp->c_tws == NULL) adios (NULL, "unable to allocate tws buffer"); *datecomp->c_tws = *dlocaltime ((time_t *) &st.st_mtime); - datecomp->c_flags = -1; + datecomp->c_flags |= CF_DATEFAB|CF_TRUE; } else { - datecomp->c_flags = 0; + datecomp->c_flags &= ~CF_DATEFAB; } } } @@ -353,8 +362,8 @@ finished: } *--nxtbuf = tmpbuf; - if (outnum && fclose (scnout) == EOF) - adios (scnmsg, "write error on"); + if (outnum && (ferror(scnout) || fclose (scnout) == EOF)) + DIEWRERR(); return (state != FILEEOF ? SCNERR : encrypted ? SCNENC : SCNMSG); }