1: /* $Header$ */
   2: 
   3: /*
   4:  * Author: Peter J. Nicklin
   5:  */
   6: 
   7: /*
   8:  * pputent() writes buffer pdbp->pbuf to a database. Returns integer NO if
   9:  * write error or buffer exceeded, otherwise YES.
  10:  */
  11: #include "stdio.h"
  12: #include "path.h"
  13: #include "pdb.h"
  14: #include "yesno.h"
  15: 
  16: pputent(pdbp)
  17:     register PDB *pdbp;     /* database stream */
  18: {
  19:     register char *bp;      /* buffer pointer */
  20:     register FILE *fp;      /* file stream */
  21:     register int i;         /* buffer counter */
  22:     char *sprintf();        /* print output to string */
  23: 
  24:     if ((pdbp->flag&_PERR) != 0)
  25:         return(NO);
  26:     if ((pdbp->flag&_PACCESS) == (_PREAD|_PWRITE))
  27:         fp = pdbp->tfp;
  28:     else if ((pdbp->flag&(_PWRITE|_PAPPEND)) != 0)
  29:         fp = pdbp->fp;
  30:     else    {
  31:         sprintf(pdbp->perr, "%s read access only", pdbp->path);
  32:         pdbp->flag |= _PERR;
  33:         return(NO);
  34:         }
  35:     i = 0;
  36:     bp = pdbp->pbuf;
  37:     pdbp->flag |= _PUPDATE;
  38: 
  39:     while (i < PBUFSIZE && *bp++ != '\0')
  40:         putc(pdbp->pbuf[i++], fp);
  41:     if (putc('\n', fp) == EOF)
  42:         {
  43:         sprintf(pdbp->perr, "%s write error", pdbp->path);
  44:         pdbp->flag |= _PERR;
  45:         return(NO);
  46:         }
  47:     if (i >= PBUFSIZE)
  48:         {
  49:         sprintf(pdbp->perr, "%s database buffer exceeded", pdbp->path);
  50:         pdbp->flag |= _PERR;
  51:         return(NO);
  52:         }
  53:     return(YES);
  54: }
Last modified: 1985-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 642
Valid CSS Valid XHTML 1.0 Strict