Author: Bleep <tomh@inxpress.net>
[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  * $Id$
20  */
21 #ifndef INCLUDED_dbuf_h
22 #define INCLUDED_dbuf_h
23 #ifndef INCLUDED_sys_types_h
24 #include <sys/types.h>          /* size_t */
25 #define INCLUDED_sys_types_h
26 #endif
27
28 /*
29  * These two globals should be considered read only
30  */
31 extern int DBufAllocCount;      /* GLOBAL - count of dbufs allocated */
32 extern int DBufUsedCount;       /* GLOBAL - count of dbufs in use */
33
34 struct DBufBuffer;
35
36 struct DBuf {
37   size_t length;                /* Current number of bytes stored */
38   struct DBufBuffer *head;      /* First data buffer, if length > 0 */
39   struct DBufBuffer *tail;      /* last data buffer, if length > 0 */
40 };
41
42 /*
43  * DBufLength - Returns the current number of bytes stored into the buffer.
44  */
45 #define DBufLength(dyn) ((dyn)->length)
46
47 /*
48  * DBufClear - Scratch the current content of the buffer.
49  * Release all allocated buffers and make it empty.
50  */
51 #define DBufClear(dyn) dbuf_delete((dyn), DBufLength(dyn))
52
53 /*
54  * Prototypes
55  */
56 extern void dbuf_delete(struct DBuf *dyn, size_t length);
57 extern int dbuf_put(struct DBuf *dyn, const char *buf, size_t length);
58 extern const char *dbuf_map(const struct DBuf *dyn, size_t *length);
59 extern size_t dbuf_get(struct DBuf *dyn, char *buf, size_t length);
60 extern size_t dbuf_getmsg(struct DBuf *dyn, char *buf, size_t length);
61 extern void dbuf_count_memory(size_t *allocated, size_t *used);
62
63
64 #endif /* INCLUDED_dbuf_h */