view buffer.h @ 102:735d6c774f7a

Reorder protos in ini.h
author David Demelier <markand@malikania.fr>
date Tue, 17 Jan 2012 12:01:22 +0100
parents 37eef6776cc6
children
line wrap: on
line source

/*
 * buffer.h -- safe unlimited size string
 *
 * Copyright (c) 2011, 2012, 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>

#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 */

	/* Own allocation functions */
	void * (*malloc)(size_t);
	void * (*realloc)(void *, size_t);
};

int	buffer_init(struct buffer *);
void	buffer_set(struct buffer *, const char *, ...);
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 *);

#endif /* _BUFFER_H_ */