From: Adam Dickmeiss Date: Sat, 6 Jan 2007 16:05:24 +0000 (+0000) Subject: Added wrbuf_cstr which returns 0-terminated WRBUF X-Git-Tag: YAZ.2.1.46~16 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=654af126f4f8e4045cde587e749df9680a4901ba;p=yaz-moved-to-github.git Added wrbuf_cstr which returns 0-terminated WRBUF --- diff --git a/include/yaz/wrbuf.h b/include/yaz/wrbuf.h index 99d82a9..f7eb963 100644 --- a/include/yaz/wrbuf.h +++ b/include/yaz/wrbuf.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: wrbuf.h,v 1.22 2007-01-06 15:32:46 adam Exp $ */ +/* $Id: wrbuf.h,v 1.23 2007-01-06 16:05:24 adam Exp $ */ /** * \file wrbuf.h @@ -76,6 +76,8 @@ YAZ_EXPORT void wrbuf_chop_right(WRBUF b); #define wrbuf_len(b) ((b)->pos) #define wrbuf_buf(b) ((b)->buf) +YAZ_EXPORT const char *wrbuf_cstr(WRBUF b); + #define wrbuf_putc(b, c) \ (((b)->pos >= (b)->size ? wrbuf_grow(b, 1) : 0), \ (b)->buf[(b)->pos++] = (c), 0) diff --git a/src/wrbuf.c b/src/wrbuf.c index b180ef0..fb5968b 100644 --- a/src/wrbuf.c +++ b/src/wrbuf.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: wrbuf.c,v 1.14 2007-01-06 15:32:46 adam Exp $ + * $Id: wrbuf.c,v 1.15 2007-01-06 16:05:24 adam Exp $ */ /** @@ -232,6 +232,13 @@ int wrbuf_iconv_write_cdata(WRBUF b, yaz_iconv_t cd, const char *buf, int size) return wrbuf_iconv_write_x(b, cd, buf, size, 1); } +const char *wrbuf_cstr(WRBUF b) +{ + wrbuf_write(b, "", 1); /* '\0'-terminate as well */ + (b->pos)--; /* don't include '\0' in count */ + return b->buf; +} + /* * Local variables: * c-basic-offset: 4