]>
Commit | Line | Data |
---|---|---|
3bd189cb JR |
1 | /************************************************************************ |
2 | * IRC - Internet Relay Chat, common/dbuf_def.h | |
3 | * Copyright (C) 1990 Markku Savela | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 1, or (at your option) | |
8 | * any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 | */ | |
19 | ||
20 | #define DBUF_TAIL | |
21 | ||
22 | /* | |
23 | ** dbuf is a collection of functions which can be used to | |
24 | ** maintain a dynamic buffering of a byte stream. | |
25 | ** Functions allocate and release memory dynamically as | |
26 | ** required [Actually, there is nothing that prevents | |
27 | ** this package maintaining the buffer on disk, either] | |
28 | */ | |
29 | ||
30 | /* | |
31 | ** These structure definitions are only here to be used | |
32 | ** as a whole, *DO NOT EVER REFER TO THESE FIELDS INSIDE | |
33 | ** THE STRUCTURES*! It must be possible to change the internal | |
34 | ** implementation of this package without changing the | |
35 | ** interface. | |
36 | */ | |
37 | #if !defined(_SEQUENT_) | |
38 | typedef struct dbuf | |
39 | { | |
40 | u_int length; /* Current number of bytes stored */ | |
41 | u_int offset; /* Offset to the first byte */ | |
42 | struct dbufbuf *head; /* First data buffer, if length > 0 */ | |
43 | #ifdef DBUF_TAIL | |
44 | /* added by mnystrom@mit.edu: */ | |
45 | struct dbufbuf *tail; /* last data buffer, if length > 0 */ | |
46 | #endif | |
47 | } dbuf; | |
48 | #else | |
49 | typedef struct dbuf | |
50 | { | |
51 | uint length; /* Current number of bytes stored */ | |
52 | uint offset; /* Offset to the first byte */ | |
53 | struct dbufbuf *head; /* First data buffer, if length > 0 */ | |
54 | #ifdef DBUF_TAIL | |
55 | /* added by mnystrom@mit.edu: */ | |
56 | struct dbufbuf *tail; /* last data buffer, if length > 0 */ | |
57 | #endif | |
58 | } dbuf; | |
59 | #endif | |
60 | /* | |
61 | ** And this 'dbufbuf' should never be referenced outside the | |
62 | ** implementation of 'dbuf'--would be "hidden" if C had such | |
63 | ** keyword... | |
64 | ** If it was possible, this would compile to be exactly 1 memory | |
65 | ** page in size. 2048 bytes seems to be the most common size, so | |
66 | ** as long as a pointer is 4 bytes, we get 2032 bytes for buffer | |
67 | ** data after we take away a bit for malloc to play with. -avalon | |
68 | */ | |
69 | typedef struct dbufbuf | |
70 | { | |
71 | struct dbufbuf *next; /* Next data buffer, NULL if this is last */ | |
72 | char data[2032]; /* Actual data stored here */ | |
73 | } dbufbuf; | |
74 | ||
75 | /* | |
76 | ** DBufLength | |
77 | ** Return the current number of bytes stored into the buffer. | |
78 | ** (One should use this instead of referencing the internal | |
79 | ** length field explicitly...) | |
80 | */ | |
81 | #define DBufLength(dyn) ((dyn)->length) | |
82 | ||
83 | /* | |
84 | ** DBufClear | |
85 | ** Scratch the current content of the buffer. Release all | |
86 | ** allocated buffers and make it empty. | |
87 | */ | |
88 | #define DBufClear(dyn) dbuf_delete((dyn),DBufLength(dyn)) | |
89 | ||
90 | /* This is a dangerous define because a broken compiler will set DBUFSIZ | |
91 | ** to 4, which will work but will be very inefficient. However, there | |
92 | ** are other places where the code breaks badly if this is screwed | |
93 | ** up, so... -- Wumpus | |
94 | */ | |
95 | ||
96 | #define DBUFSIZ sizeof(((dbufbuf *)0)->data) |