dbuffer.h

Go to the documentation of this file.
00001 /************************************************************************
00002  *   Copyright (C) Andrew Suffield <asuffield@suffields.me.uk>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation; either version 2 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with this program; if not, write to the Free Software
00016  *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00017  */
00018 
00019 #ifdef DBUFFER_H
00020 struct dbuffer;
00021 #else
00022 #define DBUFFER_H
00023 
00024 #include <sys/types.h>
00025 
00037 struct dbuffer_element;
00038 
00047 struct dbuffer
00048 {
00050     size_t len;
00051 
00054     size_t space;
00055 
00057     struct dbuffer_element *head;
00058 
00060     struct dbuffer_element *tail;
00061 
00067     char *start;
00068 
00077     char *end;
00078 
00081     struct dbuffer *next_free;
00082 };
00083 
00084 extern struct dbuffer *new_dbuffer(void) __attribute__((malloc));
00085 extern void free_dbuffer(struct dbuffer *);
00086 
00087 /* Append the given byte string to the buffer */
00088 extern void dbuffer_add(struct dbuffer *, const char *, size_t);
00089 /* Read the given number of bytes from the start of the buffer */
00090 extern size_t dbuffer_get(const struct dbuffer *, char *, size_t);
00091 /* Read the given number of bytes from the given position */
00092 extern size_t dbuffer_get_at(const struct dbuffer *, size_t, char *, size_t);
00093 /* Remove the given number of bytes from the start of the buffer */
00094 extern size_t dbuffer_remove(struct dbuffer *, size_t);
00095 /* Read and remove in one pass */
00096 extern size_t dbuffer_extract(struct dbuffer *, char *, size_t);
00097 /* Duplicate the buffer */
00098 extern struct dbuffer *dbuffer_dup(struct dbuffer *);
00099 /* Duplicate the buffer and prepend the given data */
00100 extern struct dbuffer *dbuffer_prepend(struct dbuffer *old, const char *data, size_t len);
00101 /* Merges two dbuffers */
00102 struct dbuffer *dbuffer_merge(struct dbuffer *old, struct dbuffer *old2);
00103 
00104 void dbuffer_shutdown(void);
00105 void dbuffer_init(void);
00106 
00107 #define dbuffer_len(A) (A ? (A)->len : 0)
00108 
00109 #endif

Generated by  doxygen 1.6.2