PHPSTR_API size_t phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size)
{
+#if 0
+ fprintf(stderr, "RESIZE: size=%lu, used=%lu, free=%lu\n", buf->size, buf->used, buf->free);
+#endif
if (buf->free < len) {
size_t size = override_size ? override_size : buf->size;
return 0;
}
+PHPSTR_API size_t phpstr_shrink(phpstr *buf)
+{
+ /* avoid another realloc on fixation */
+ if (buf->free > 1) {
+ char *ptr = perealloc(buf->data, buf->used + 1, buf->pmem);
+
+ if (ptr) {
+ buf->data = ptr;
+ } else {
+ return NOMEM;
+ }
+ buf->free = 1;
+ }
+ return buf->used;
+}
+
PHPSTR_API size_t phpstr_append(phpstr *buf, const char *append, size_t append_len)
{
if (NOMEM == phpstr_resize(buf, append_len)) {