X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=phpstr%2Fphpstr.c;h=8d8df3ea25f383cf1e9ec1efe9f0b73d495a4654;hp=af090fa02d16aadb2d1139e9c3f3ba9e168d7175;hb=909134d3309bdc12023c0fea5acf931041ea0f6b;hpb=af674f03c32f0f56b7f8c67e61c7e86b3ea23be5 diff --git a/phpstr/phpstr.c b/phpstr/phpstr.c index af090fa..8d8df3e 100644 --- a/phpstr/phpstr.c +++ b/phpstr/phpstr.c @@ -11,7 +11,7 @@ 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; @@ -22,7 +22,7 @@ PHPSTR_API phpstr *phpstr_init_ex(phpstr *buf, size_t chunk_size, zend_bool pre_ 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); @@ -45,12 +45,13 @@ PHPSTR_API void phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size) } } -PHPSTR_API void phpstr_append(phpstr *buf, const char *append, size_t append_len) +PHPSTR_API size_t phpstr_append(phpstr *buf, const char *append, size_t append_len) { phpstr_resize(buf, append_len); memcpy(buf->data + buf->used, append, append_len); buf->used += append_len; buf->free -= append_len; + return append_len; } PHPSTR_API size_t phpstr_appendf(phpstr *buf, const char *format, ...) @@ -69,13 +70,14 @@ PHPSTR_API size_t phpstr_appendf(phpstr *buf, const char *format, ...) return append_len; } -PHPSTR_API void phpstr_insert(phpstr *buf, const char *insert, size_t insert_len, size_t offset) +PHPSTR_API size_t phpstr_insert(phpstr *buf, const char *insert, size_t insert_len, size_t offset) { phpstr_resize(buf, insert_len); memmove(buf->data + offset + insert_len, buf->data + offset, insert_len); memcpy(buf->data + offset, insert, insert_len); buf->used += insert_len; buf->free -= insert_len; + return insert_len; } PHPSTR_API size_t phpstr_insertf(phpstr *buf, size_t offset, const char *format, ...) @@ -94,13 +96,14 @@ PHPSTR_API size_t phpstr_insertf(phpstr *buf, size_t offset, const char *format, return insert_len; } -PHPSTR_API void phpstr_prepend(phpstr *buf, const char *prepend, size_t prepend_len) +PHPSTR_API size_t phpstr_prepend(phpstr *buf, const char *prepend, size_t prepend_len) { phpstr_resize(buf, prepend_len); memmove(buf->data + prepend_len, buf->data, buf->used); memcpy(buf->data, prepend, prepend_len); buf->used += prepend_len; buf->free -= prepend_len; + return prepend_len; } PHPSTR_API size_t phpstr_prependf(phpstr *buf, const char *format, ...) @@ -139,10 +142,10 @@ PHPSTR_API phpstr *phpstr_dup(const phpstr *buf) 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;