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