/*
- * Copyright (C) 1995-2005, Index Data ApS
+ * Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: wrbuf.c,v 1.11 2006-07-07 10:31:26 marc Exp $
+ * $Id: wrbuf.c,v 1.17 2007-03-18 12:59:56 adam Exp $
*/
/**
#include <stdarg.h>
#include <yaz/wrbuf.h>
+#include <yaz/snprintf.h>
#include <yaz/yaz-iconv.h>
WRBUF wrbuf_alloc(void)
xfree(b);
}
+void wrbuf_destroy(WRBUF b)
+{
+ wrbuf_free(b, 1);
+}
+
void wrbuf_rewind(WRBUF b)
{
b->pos = 0;
char buf[4096];
va_start(ap, fmt);
-#ifdef WIN32
- _vsnprintf(buf, sizeof(buf)-1, fmt, ap);
-#else
-/* !WIN32 */
-#if HAVE_VSNPRINTF
- vsnprintf(buf, sizeof(buf)-1, fmt, ap);
-#else
- vsprintf(buf, fmt, ap);
-#endif
-#endif
+ yaz_vsnprintf(buf, sizeof(buf)-1, fmt, ap);
wrbuf_puts (b, buf);
va_end(ap);
return wrbuf_iconv_write(b, cd, strz, strlen(strz));
}
+int wrbuf_iconv_putchar(WRBUF b, yaz_iconv_t cd, int ch)
+{
+ char buf[1];
+ buf[0] = ch;
+ return wrbuf_iconv_write(b, cd, buf, 1);
+}
+
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;
+}
+
+void wrbuf_cut_right(WRBUF b, size_t no_to_remove)
+{
+ if (no_to_remove > b->pos)
+ no_to_remove = b->pos;
+ b->pos = b->pos - no_to_remove;
+}
+
/*
* Local variables:
* c-basic-offset: 4