projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cs_get_host_args: allow unix:path:args notation
[yaz-moved-to-github.git]
/
src
/
wrbuf.c
diff --git
a/src/wrbuf.c
b/src/wrbuf.c
index
3c63170
..
6d9b145
100644
(file)
--- a/
src/wrbuf.c
+++ b/
src/wrbuf.c
@@
-31,6
+31,7
@@
WRBUF wrbuf_alloc(void)
n->buf = 0;
n->size = 0;
n->pos = 0;
n->buf = 0;
n->size = 0;
n->pos = 0;
+ wrbuf_grow(n, 1);
return n;
}
return n;
}
@@
-58,9
+59,8
@@
int wrbuf_grow(WRBUF b, size_t minsize)
togrow = b->size;
if (togrow < minsize)
togrow = minsize;
togrow = b->size;
if (togrow < minsize)
togrow = minsize;
- if (b->size && !(b->buf =(char *)xrealloc(b->buf, b->size += togrow)))
- abort();
- else if (!b->size && !(b->buf = (char *)xmalloc(b->size = togrow)))
+ b->buf = (char *) xrealloc(b->buf, 1 + (b->size += togrow));
+ if (!b->buf)
abort();
return 0;
}
abort();
return 0;
}
@@
-70,7
+70,7
@@
void wrbuf_write(WRBUF b, const char *buf, size_t size)
if (size <= 0)
return;
if (b->pos + size >= b->size)
if (size <= 0)
return;
if (b->pos + size >= b->size)
- wrbuf_grow(b, size + 1);
+ wrbuf_grow(b, size);
memcpy(b->buf + b->pos, buf, size);
b->pos += size;
}
memcpy(b->buf + b->pos, buf, size);
b->pos += size;
}
@@
-80,7
+80,7
@@
void wrbuf_insert(WRBUF b, size_t pos, const char *buf, size_t size)
if (size <= 0 || pos > b->pos)
return;
if (b->pos + size >= b->size)
if (size <= 0 || pos > b->pos)
return;
if (b->pos + size >= b->size)
- wrbuf_grow(b, size + 1);
+ wrbuf_grow(b, size);
memmove(b->buf + pos + size, b->buf + pos, b->pos - pos);
memcpy(b->buf + pos, buf, size);
b->pos += size;
memmove(b->buf + pos + size, b->buf + pos, b->pos - pos);
memcpy(b->buf + pos, buf, size);
b->pos += size;
@@
-263,9
+263,16
@@
void wrbuf_iconv_reset(WRBUF b, yaz_iconv_t cd)
const char *wrbuf_cstr(WRBUF b)
{
const char *wrbuf_cstr(WRBUF b)
{
- if (b->pos == 0)
- return "";
- assert(b->pos < b->size);
+ assert(b && b->pos <= b->size);
+ b->buf[b->pos] = '\0';
+ return b->buf;
+}
+
+const char *wrbuf_cstr_null(WRBUF b)
+{
+ if (!b || b->pos == 0)
+ return 0;
+ assert(b->pos <= b->size);
b->buf[b->pos] = '\0';
return b->buf;
}
b->buf[b->pos] = '\0';
return b->buf;
}