# 2.11BSD#431 - /usr/ingres/source/gutil/need.c

##### Functions

    initbuf           X
    need              X

##### struct's

    nodbuffer         X

       1: /*
       2: **  NEED.C -- general buffer allocation routines
       3: **
       4: **	allow buffers with LIFO de-allocation
       5: **
       6: **	Defines:
       7: **		need()
       8: **		initbuf()
       9: **
      10: **	History:
      11: **		10/10/78 -- (marc) modified from need in ovqp.
      12: **			New are : err_num, err_func stuff, and
      13: **			seterr().
      14: */
      15:
      16:
      17:
      18:
      19:
      20:
      21: /* structure that the routines use to allocate space */
      22: struct nodbuffer
      23: {
      24:     int     nleft;      /* bytes left */
      25:     int     err_num;    /* error code on overflow */
      26:     int     (*err_func)();  /* error function on overflow */
      27:     char        *xfree;     /* next free byte */
      28:     char        buffer [];  /*beginning of buffer area */
      29: };
      30:
      31: /*
      32: **  NEED -- allocate space from a buffer
      33: **
      34: **	On buffer overflow, calls err_func from that field
      35: **	in the buffer with the error code err_code from that field
      36: **	in the buffer, then returns 0.
      37: **	need() guarantees an even adress on return.
      38: **
      39: **	Parameters:
      40: **		bf -- buffer
      41: **		nbytes -- number of bytes desired
      42: **
      43: **	Returns:
      44: **		pointer to allocated area
      45: **		on  buffer overflow returns 0.
      46: **
      47: **	Side Effects:
      48: **		adjusts buffer structure to reflect allocation.
      49: **
      50: */
      51:
      52: char *
      53: need(bf, nbytes)
      54: struct nodbuffer    *bf;
      55: int         nbytes;
      56: {
      57:     register char           *x;
      58:     register struct nodbuffer   *buf;
      59:     register int            i;
      60:
      61:     buf = bf;
      62:     i = nbytes;
      63:     if (i > buf->nleft)
      64:     {
      65:             (*buf->err_func)(buf->err_num);
      66:             return (0);
      67:     }
      68:     i += i & 01;
      69:     x = buf->xfree;
      70:     buf->xfree += i;
      71:     buf->nleft -= i;
      72:     return(x);
      73: }
      74:
      75: /*
      76: **  INITBUF -- initialize a buffer
      77: **
      78: **	Must be called before the first need() call on the buffer.
      79: **
      80: **	Parameters:
      81: **		bf -- buffer
      82: **		size -- size fo buffer area
      83: **		err_num -- error code for overflow
      84: **		err_func -- function to call with err_code on error
      85: **
      86: **	Returns:
      87: **		none
      88: **
      89: **	Side Effects:
      90: **		initializes buffer structure
      91: **
      92: **	Diagnostics:
      93: **		"initbuf : odd buffer adress 0%o" -- buffers must start
      94: **			at an even adress.
      95: */
      96:
      97: initbuf(bf, size, err_num, err_func)
      98: struct nodbuffer    *bf;
      99: int         size;
     100: int         err_num;
     101: int         (*err_func)();
     102: {
     103:     register struct nodbuffer   *buf;
     104:
     105:     buf = bf;
     106:     if ((unsigned int) buf & 01)
     107:         syserr("initbuf : odd buffer adress 0%o", buf);
     108:     buf->nleft = size - sizeof *buf;
     109:     buf->xfree = buf->buffer;
     110:     buf->err_num = err_num;
     111:     buf->err_func = err_func;
     112: }

#### Defined functions

initbuf defined in line 97; used 11 times

- in /usr/ingres/source/dbu/readtree.c line 101
- in /usr/ingres/source/decomp/ageval.c line 57
- in /usr/ingres/source/decomp/byeval.c line 131
- in /usr/ingres/source/decomp/call_ovqp70.c line 147
- in /usr/ingres/source/decomp/decomp.c line 104
- in /usr/ingres/source/decomp/qryproc.c line 34
- in /usr/ingres/source/ovqp/getqry.c line 53
- in /usr/ingres/source/parser/call_p.c line 57
- in /usr/ingres/source/parser/control.c line 48
- in /usr/ingres/source/qrymod/readtree.c line 78
- in /usr/ingres/source/scanner/symtab.c line 32

need defined in line 52; used 62 times

- in /usr/ingres/source/dbu/readtree.c line 162-165(2), 175, 202-209(3)
- in /usr/ingres/source/decomp/aggregate.c line 288-293(2)
- in /usr/ingres/source/decomp/byeval.c line 274, 284, 292
- in /usr/ingres/source/decomp/call_ovqp70.c line 284, 296
- in /usr/ingres/source/decomp/decomp.c line 156, 176
- in /usr/ingres/source/decomp/makenode.c line 7, 28, 54-59(2), 82, 99, 122
- in /usr/ingres/source/decomp/readq.c line 87-89(2), 98, 113, 119
- in /usr/ingres/source/decomp/reduction.c line 134-141(3)
- in /usr/ingres/source/decomp/tempvar.c line 43, 58
- in /usr/ingres/source/ovqp/findsimps.c line 291-294(2)
- in /usr/ingres/source/ovqp/rdsym.c line 22-24(2), 39, 86, 93
- in /usr/ingres/source/ovqp/string.c line 37, 52, 111, 149
- in /usr/ingres/source/parser/call_p.c line 40-43(2), 55-58(2)
- in /usr/ingres/source/parser/norml.c line 314
- in /usr/ingres/source/parser/tree.c line 26, 35
- in /usr/ingres/source/qrymod/readtree.c line 144-147(2), 157, 181-188(3)
- in /usr/ingres/source/qrymod/tree.c line 44-49(2)
- in /usr/ingres/source/qrymod/util.c line 478, 506
- in /usr/ingres/source/scanner/symtab.c line 16-19(2)

#### Defined struct's

nodbuffer defined in line 22; used 8 times

- in line 54-58(4), 98-103(4)

Last modified: 1995-02-09 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 510 |