X-Git-Url: http://git.pk910.de/?p=ircu2.10.12-pk.git;a=blobdiff_plain;f=include%2Fdbuf.h;fp=include%2Fdbuf.h;h=057ff2a6a691a6acb4560c5b66baa03f117dc04d;hp=0000000000000000000000000000000000000000;hb=0400a5a6479398d82526785c18c0df8bc8b92dce;hpb=d17e10da972ce5776c60b4c317267c6abe0e1ead diff --git a/include/dbuf.h b/include/dbuf.h new file mode 100644 index 0000000..057ff2a --- /dev/null +++ b/include/dbuf.h @@ -0,0 +1,62 @@ +/* + * IRC - Internet Relay Chat, include/dbuf.h + * Copyright (C) 1990 Markku Savela + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/** @file + * @brief Interfaces and declarations for dealing with data buffers. + * @version $Id$ + */ +#ifndef INCLUDED_dbuf_h +#define INCLUDED_dbuf_h +#ifndef INCLUDED_sys_types_h +#include /* size_t */ +#define INCLUDED_sys_types_h +#endif + +/* + * These two globals should be considered read only + */ +extern int DBufAllocCount; +extern int DBufUsedCount; + +struct DBufBuffer; + +/** Queue of data chunks. */ +struct DBuf { + unsigned int length; /**< Current number of bytes stored */ + struct DBufBuffer *head; /**< First data buffer, if length > 0 */ + struct DBufBuffer *tail; /**< Last data buffer, if length > 0 */ +}; + +/** Return number of bytes in a DBuf. */ +#define DBufLength(dyn) ((dyn)->length) + +/** Release the entire content of a DBuf. */ +#define DBufClear(dyn) dbuf_delete((dyn), DBufLength(dyn)) + +/* + * Prototypes + */ +extern void dbuf_delete(struct DBuf *dyn, unsigned int length); +extern int dbuf_put(struct DBuf *dyn, const char *buf, unsigned int length); +extern const char *dbuf_map(const struct DBuf *dyn, unsigned int *length); +extern unsigned int dbuf_get(struct DBuf *dyn, char *buf, unsigned int length); +extern unsigned int dbuf_getmsg(struct DBuf *dyn, char *buf, unsigned int length); +extern void dbuf_count_memory(size_t *allocated, size_t *used); + + +#endif /* INCLUDED_dbuf_h */