]> jfr.im git - irc/quakenet/snircd.git/blob - include/dbuf.h
Initial import of 2.10.12.01
[irc/quakenet/snircd.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 /** @file
20 * @brief Interfaces and declarations for dealing with data buffers.
21 * @version $Id: dbuf.h,v 1.7 2004/10/05 00:51:56 entrope Exp $
22 */
23 #ifndef INCLUDED_dbuf_h
24 #define INCLUDED_dbuf_h
25 #ifndef INCLUDED_sys_types_h
26 #include <sys/types.h> /* size_t */
27 #define INCLUDED_sys_types_h
28 #endif
29
30 /*
31 * These two globals should be considered read only
32 */
33 extern int DBufAllocCount;
34 extern int DBufUsedCount;
35
36 struct DBufBuffer;
37
38 /** Queue of data chunks. */
39 struct DBuf {
40 unsigned int length; /**< Current number of bytes stored */
41 struct DBufBuffer *head; /**< First data buffer, if length > 0 */
42 struct DBufBuffer *tail; /**< Last data buffer, if length > 0 */
43 };
44
45 /** Return number of bytes in a DBuf. */
46 #define DBufLength(dyn) ((dyn)->length)
47
48 /** Release the entire content of a DBuf. */
49 #define DBufClear(dyn) dbuf_delete((dyn), DBufLength(dyn))
50
51 /*
52 * Prototypes
53 */
54 extern void dbuf_delete(struct DBuf *dyn, unsigned int length);
55 extern int dbuf_put(struct DBuf *dyn, const char *buf, unsigned int length);
56 extern const char *dbuf_map(const struct DBuf *dyn, unsigned int *length);
57 extern unsigned int dbuf_get(struct DBuf *dyn, char *buf, unsigned int length);
58 extern unsigned int dbuf_getmsg(struct DBuf *dyn, char *buf, unsigned int length);
59 extern void dbuf_count_memory(size_t *allocated, size_t *used);
60
61
62 #endif /* INCLUDED_dbuf_h */