Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Zend/zend_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,43 @@ static zend_always_inline zend_string *zend_string_safe_realloc(zend_string *s,
return ret;
}

static zend_always_inline char *zend_cstr_append_char(const char *str, size_t len, char c) {
char *res = (char *)safe_emalloc(len, 1, 2);
if (len > 0) {
memcpy(res, str, len);
}
res[len] = c;
res[len + 1] = '\0';
return res;
}

static zend_always_inline char *zend_cstr_concat(const char *s1, size_t len1, const char *s2, size_t len2) {
char *res = (char *)safe_emalloc(len1, 1, len2 + 1);
if (len1 > 0) {
memcpy(res, s1, len1);
}
if (len2 > 0) {
memcpy(res + len1, s2, len2);
}
res[len1 + len2] = '\0';
return res;
}

static zend_always_inline char *zend_cstr_concat3(const char *s1, size_t len1, const char *s2, size_t len2, const char *s3, size_t len3) {
char *res = (char *)safe_emalloc(len1, 1, len2 + len3 + 1);
if (len1 > 0) {
memcpy(res, s1, len1);
}
if (len2 > 0) {
memcpy(res + len1, s2, len2);
}
if (len3 > 0) {
memcpy(res + len1 + len2, s3, len3);
}
res[len1 + len2 + len3] = '\0';
return res;
}

static zend_always_inline void zend_string_free(zend_string *s)
{
if (!ZSTR_IS_INTERNED(s)) {
Expand Down
Loading