2 * $Id: printbuf.h,v 1.4 2006/01/26 02:16:28 mclark Exp $
4 * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
5 * Michael Clark <michael@metaparadigm.com>
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the MIT license. See COPYING for details.
11 * Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved.
12 * The copyrights to the contents of this file are licensed under the MIT License
13 * (http://www.opensource.org/licenses/mit-license.php)
29 extern struct printbuf
*
32 /* As an optimization, printbuf_memappend_fast is defined as a macro
33 * that handles copying data if the buffer is large enough; otherwise
34 * it invokes printbuf_memappend_real() which performs the heavy
35 * lifting of realloc()ing the buffer and copying data.
36 * Your code should not use printbuf_memappend directly--use
37 * printbuf_memappend_fast instead.
40 printbuf_memappend(struct printbuf
*p
, const char *buf
, int size
);
42 #define printbuf_memappend_fast(p, bufptr, bufsize) \
44 if ((p->size - p->bpos) > bufsize) { \
45 memcpy(p->buf + p->bpos, (bufptr), bufsize); \
47 p->buf[p->bpos]= '\0'; \
48 } else { printbuf_memappend(p, (bufptr), bufsize); } \
51 #define printbuf_length(p) ((p)->bpos)
54 * Set len bytes of the buffer to charvalue, starting at offset offset.
55 * Similar to calling memset(x, charvalue, len);
57 * The memory allocated for the buffer is extended as necessary.
59 * If offset is -1, this starts at the end of the current data in the buffer.
62 printbuf_memset(struct printbuf
*pb
, int offset
, int charvalue
, int len
);
65 sprintbuf(struct printbuf
*p
, const char *msg
, ...);
68 printbuf_reset(struct printbuf
*p
);
71 printbuf_free(struct printbuf
*p
);