1: # include   "ctlmod.h"
   2: # include   "pipes.h"
   3: # include   <sccs.h>
   4: 
   5: SCCSID(@(#)pb_get.c	8.1	12/31/84)
   6: 
   7: /*
   8: **  PB_GET -- buffered get from pipe
   9: **
  10: **	This routine just gets a record from the pipe block, reading
  11: **	if necessary.  It tries to do things in big chunks to keep
  12: **	the overhead down.
  13: **
  14: **	Parameters:
  15: **		ppb -- a pointer to the pipe block to unbuffer.
  16: **		dp -- a pointer to the data area.
  17: **		len -- the number of bytes to read.
  18: **
  19: **	Returns:
  20: **		The number of bytes actually read.
  21: **		Zero on end of file.
  22: **
  23: **	Side Effects:
  24: **		none.
  25: **
  26: **	Trace Flags:
  27: **		18.1 - 18.7
  28: */
  29: 
  30: pb_get(ppb, dp, len)
  31: register pb_t   *ppb;
  32: char        *dp;
  33: register int    len;
  34: {
  35:     int     rct;
  36:     register int    i;
  37: 
  38:     rct = 0;
  39: # ifdef xCTR2
  40:     if (tTf(18, 1))
  41:         lprintf("pb_get: ");
  42: # endif
  43: 
  44:     /*
  45: 	**  Top Loop.
  46: 	**	As long as we still want more, keep buffering out.
  47: 	*/
  48: 
  49:     while (len > 0)
  50:     {
  51:         /* if we have no data, read another block */
  52:         while (ppb->pb_nleft <= 0)
  53:         {
  54:             if (bitset(PB_EOF, ppb->pb_stat))
  55:             {
  56: # ifdef xCTR2
  57:                 if (tTf(18, 1))
  58:                     printf("EOF\n");
  59: # endif
  60:                 if (rct != 0)
  61:                     syserr("pb_get: EOF");
  62:                 return (rct);
  63:             }
  64:             pb_read(ppb);
  65:         }
  66: 
  67:         /*
  68: 		**  Compute the length to move.
  69: 		**	This is the min of the amount we want and the
  70: 		**	amount we have available to us in the buffer.
  71: 		*/
  72: 
  73:         i = min(ppb->pb_nleft, len);
  74:         bmove(ppb->pb_xptr, dp, i);
  75:         ppb->pb_xptr += i;
  76:         ppb->pb_nleft -= i;
  77:         dp += i;
  78:         len -= i;
  79:         rct += i;
  80:     }
  81: 
  82: # ifdef xCTR2
  83:     if (tTf(18, 1))
  84:         printf("%d\n", rct);
  85: # endif
  86:     return (rct);
  87: }

Defined functions

Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 903
Valid CSS Valid XHTML 1.0 Strict