root/src/json-lib/printbuf.h

Revision 351020b260749e2e97fda8f50a3bb37dcf1d0e34, 1.7 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 11 months ago)

namespace these more reasonably (no functional change)

  • Property mode set to 100644
Line 
1 /*
2  * $Id: printbuf.h,v 1.4 2006/01/26 02:16:28 mclark Exp $
3  *
4  * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
5  * Michael Clark <michael@metaparadigm.com>
6  *
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.
9  *
10  *
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)
14  */
15
16 #ifndef _printbuf_h_
17 #define _printbuf_h_
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 #undef PRINTBUF_DEBUG
24
25 struct jl_printbuf {
26   char *buf;
27   int bpos;
28   int size;
29 };
30
31 extern struct jl_printbuf*
32 jl_printbuf_new(void);
33
34 /* As an optimization, jl_printbuf_memappend is defined as a macro that
35  * handles copying data if the buffer is large enough; otherwise it
36  * invokes jl_printbuf_memappend_real() which performs the heavy lifting
37  * of realloc()ing the buffer and copying data.
38  */
39 extern int
40 jl_printbuf_memappend(struct jl_printbuf *p, const char *buf, int size);
41
42 #define jl_printbuf_memappend_fast(p, bufptr, bufsize)          \
43 do {                                                         \
44   if ((p->size - p->bpos) > bufsize) {                       \
45     memcpy(p->buf + p->bpos, (bufptr), bufsize);             \
46     p->bpos += bufsize;                                      \
47     p->buf[p->bpos]= '\0';                                   \
48   } else {  jl_printbuf_memappend(p, (bufptr), bufsize); }      \
49 } while (0)
50
51 extern int
52 jl_sprintbuf(struct jl_printbuf *p, const char *msg, ...);
53
54 extern void
55 jl_printbuf_reset(struct jl_printbuf *p);
56
57 extern void
58 jl_printbuf_free(struct jl_printbuf *p);
59
60 #ifdef __cplusplus
61 }
62 #endif
63
64 #endif
Note: See TracBrowser for help on using the browser.