PHPSTR_API phpstr *phpstr_init_ex(phpstr *buf, size_t chunk_size, zend_bool pre_alloc)
{
if (!buf) {
- buf = ecalloc(1, sizeof(phpstr));
+ buf = emalloc(sizeof(phpstr));
}
buf->size = chunk_size > 0 ? chunk_size : PHPSTR_DEFAULT_SIZE;
return buf;
}
-PHPSTR_API phpstr *phpstr_from_string_ex(phpstr *buf, char *string, size_t length)
+PHPSTR_API phpstr *phpstr_from_string_ex(phpstr *buf, const char *string, size_t length)
{
buf = phpstr_init(buf);
phpstr_append(buf, string, length);
return dup;
}
-PHPSTR_API ssize_t phpstr_cut(phpstr *buf, size_t offset, size_t length)
+PHPSTR_API size_t phpstr_cut(phpstr *buf, size_t offset, size_t length)
{
if (offset >= buf->used) {
- return -1;
+ return 0;
}
if (offset + length > buf->used) {
length = buf->used - offset;