This commit was generated by cvs2svn to compensate for changes in r2,
[ircu2.10.12-pk.git] / include / dbuf.h
1 /*
2  * IRC - Internet Relay Chat, include/dbuf.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 2, 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 #ifndef INCLUDED_dbuf_h
20 #define INCLUDED_dbuf_h
21 #ifndef INCLUDED_sys_types_h
22 #include <sys/types.h>          /* size_t */
23 #define INCLUDED_sys_types_h
24 #endif
25
26 /*
27  * These two globals should be considered read only
28  */
29 extern int DBufAllocCount;      /* GLOBAL - count of dbufs allocated */
30 extern int DBufUsedCount;       /* GLOBAL - count of dbufs in use */
31
32 struct DBufBuffer;
33
34 struct DBuf {
35   size_t length;                /* Current number of bytes stored */
36   struct DBufBuffer *head;      /* First data buffer, if length > 0 */
37   struct DBufBuffer *tail;      /* last data buffer, if length > 0 */
38 };
39
40 /*
41  * DBufLength - Returns the current number of bytes stored into the buffer.
42  */
43 #define DBufLength(dyn) ((dyn)->length)
44
45 /*
46  * DBufClear - Scratch the current content of the buffer.
47  * Release all allocated buffers and make it empty.
48  */
49 #define DBufClear(dyn) dbuf_delete((dyn), DBufLength(dyn))
50
51 /*
52  * Prototypes
53  */
54 extern void dbuf_delete(struct DBuf *dyn, size_t length);
55 extern int dbuf_put(struct DBuf *dyn, const char *buf, size_t length);
56 extern const char *dbuf_map(const struct DBuf *dyn, size_t *length);
57 extern size_t dbuf_get(struct DBuf *dyn, char *buf, size_t length);
58 extern size_t dbuf_getmsg(struct DBuf *dyn, char *buf, size_t length);
59 extern void dbuf_count_memory(size_t *allocated, size_t *used);
60
61
62 #endif /* INCLUDED_dbuf_h */