1: /*
   2: **  FREEBUF.C -- more routines for LIFO dynamic buffer allocation [need.c]
   3: **
   4: **	These routines allow the deallocation of a need() type buffer,
   5: **	and also using the same buffer for various SERIALIZED purposes
   6: **	by marking the end of one, beginning of the next.
   7: **
   8: **	Defines:
   9: **		freebuf()
  10: **		markbuf()
  11: **		seterr()
  12: **
  13: **	Requires:
  14: **		that the buffer structure be IDENTICAL to that in [need.c]
  15: **
  16: **	History:
  17: **		10/12/78 -- (marc) separated from [need.c] so that processes
  18: **			not using more that need() and initbuf() wouldn't load
  19: **			it.
  20: */
  21: 
  22: 
  23: 
  24: 
  25: 
  26: 
  27: /* structure that the routines use to allocate space */
  28: struct nodbuffer
  29: {
  30:     int     nleft;      /* bytes left */
  31:     int     err_num;    /* error code on overflow */
  32:     int     (*err_func)();  /* error function on overflow */
  33:     char        *xfree;     /* next free byte */
  34:     char        buffer [];  /*beginning of buffer area */
  35: };
  36: 
  37: /*
  38: **  MARKBUF -- Mark a place in the buffer to deallocate to
  39: **
  40: **	Parameters:
  41: **		bf -- buffer
  42: **
  43: **	Returns:
  44: **		int >= 0 marking place in buffer (should be used in calling
  45: **			freebuf())
  46: **
  47: **	Side Effects:
  48: **		none
  49: */
  50: 
  51: markbuf(bf)
  52: struct nodbuffer    *bf;
  53: {
  54:     register struct nodbuffer   *buf;
  55: 
  56:     buf = bf;
  57:     return (buf->nleft);
  58: }
  59: 
  60: 
  61: /*
  62: **  FREEBUF -- frees part of a buffer
  63: **
  64: **	Parameters:
  65: **		bf -- buffer
  66: **		bytes -- a previous return from markbuf().
  67: **
  68: **	Returns:
  69: **		none
  70: **
  71: **	Side Effects:
  72: **		none
  73: */
  74: 
  75: freebuf(bf, bytes)
  76: struct nodbuffer    *bf;
  77: int         bytes;
  78: {
  79:     register struct nodbuffer   *buf;
  80:     register int            i;
  81: 
  82:     buf = bf;
  83:     i = bytes - buf->nleft;
  84:     if (i < 0)
  85:         syserr("freebuf %d, %d", i, bytes);
  86:     buf->xfree -= i;
  87:     buf->nleft += i;
  88: }
  89: 
  90: /*
  91: **  SETERR -- change the error info for a buffer
  92: **
  93: **	Parameters:
  94: **		bf -- buffer
  95: **		errnum -- new overflow error code
  96: **		err_func -- new error handler
  97: **
  98: **	Returns:
  99: **		none
 100: **
 101: **	Side Effects:
 102: **		adjusts buffer structure
 103: */
 104: 
 105: seterr(bf, errnum, err_func)
 106: struct nodbuffer    *bf;
 107: int         errnum;
 108: int         (*err_func)();
 109: {
 110:     register struct nodbuffer   *buf;
 111:     register int            (*erf)();
 112: 
 113:     buf = bf;
 114:     erf = err_func;
 115:     buf->err_num = errnum;
 116:     bf->err_func = erf;
 117: }
Last modified: 1995-02-09
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1978
Valid CSS Valid XHTML 1.0 Strict