Mercurial > code
view buffer.h @ 86:ff1fcb6e385f
Fix a possible infinite loop
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 20 Nov 2011 18:08:11 +0100 |
parents | 580d76781c9e |
children | b1a084c030c8 |
line wrap: on
line source
/* * buffer.h -- safe unlimited size string * * Copyright (c) 2011, David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef _BUFFER_H_ #define _BUFFER_H_ #include <stdarg.h> #ifdef __cplusplus extern "C" { #endif #define BUFFER_DEFAULT_BSIZE 512 enum buffer_type { BUFFER_FIXED = 0, BUFFER_AUTO = 1 }; struct buffer { enum buffer_type type; /* buffer type (default AUTO) */ char *text; /* string buffer */ size_t length; /* string's real length */ size_t size; /* current allocated size */ int bsize; /* initial length */ }; struct buffer *buffer_new(enum buffer_type, int); int buffer_strcat(struct buffer *, const char *); int buffer_putc(struct buffer *buf, char); int buffer_bcat(struct buffer *, const void *, size_t); int buffer_vprintf(struct buffer *, const char *, va_list); int buffer_printf(struct buffer *, const char *, ...); int buffer_shrink(struct buffer *); char *buffer_end(struct buffer *); void buffer_clear(struct buffer *); void buffer_free(struct buffer *); #ifdef __cplusplus } #endif #endif /* _BUFFER_H_ */