+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;
+}
+