2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 1999-11-03 09:05:56 adam
8 * Implemented wrbuf_puts.
10 * Revision 1.6 1999/10/28 11:36:40 adam
11 * wrbuf_write allows zero buffer length.
13 * Revision 1.5 1999/08/27 09:40:32 adam
14 * Renamed logf function to yaz_log. Removed VC++ project files.
16 * Revision 1.4 1998/02/11 11:53:36 adam
17 * Changed code so that it compiles as C++.
19 * Revision 1.3 1997/05/01 15:08:15 adam
20 * Added log_mask_str_x routine.
22 * Revision 1.2 1995/11/01 13:55:06 quinn
25 * Revision 1.1 1995/10/06 08:51:25 quinn
32 * Growing buffer for writing various stuff.
40 WRBUF wrbuf_alloc(void)
44 if (!(n = (WRBUF)xmalloc(sizeof(*n))))
52 void wrbuf_free(WRBUF b, int free_buf)
54 if (free_buf && b->buf)
59 void wrbuf_rewind(WRBUF b)
64 int wrbuf_grow(WRBUF b, int minsize)
74 if (b->size && !(b->buf =(char *)xrealloc(b->buf, b->size += togrow)))
76 else if (!b->size && !(b->buf = (char *)xmalloc(b->size = togrow)))
81 int wrbuf_write(WRBUF b, const char *buf, int size)
85 if (b->pos + size >= b->size)
87 memcpy(b->buf + b->pos, buf, size);
92 int wrbuf_puts(WRBUF b, const char *buf)
94 wrbuf_write(b, buf, strlen(buf)+1); /* '\0'-terminate as well */
95 (b->pos)--; /* don't include '\0' in count */