Browse Source

MT#61822 refactor str_dup_str

... in terms of newly added str_dup_len

Change-Id: I02fcd921fe353c2435daf6dccd7effc55fb1f43b
pull/1897/head
Richard Fuchs 11 months ago
parent
commit
cc99aa7df3
1 changed files with 8 additions and 5 deletions
  1. +8
    -5
      lib/str.h

+ 8
- 5
lib/str.h View File

@ -298,14 +298,17 @@ INLINE int str_cmp_str0(const str *a, const str *b) {
}
return str_cmp_str(a, b);
}
INLINE str str_dup_len(const char *s, size_t len) {
char *buf = g_malloc(len + 1);
if (s && len)
memcpy(buf, s, len);
buf[len] = '\0';
return STR_LEN(buf, len);
}
INLINE str str_dup_str(const str *s) {
if (!s)
return STR_NULL;
char *buf = g_malloc(s->len + 1);
if (s->s && s->len)
memcpy(buf, s->s, s->len);
buf[s->len] = '\0';
return STR_LEN(buf, s->len);
return str_dup_len(s->s, s->len);
}
INLINE void str_free_dup(str *out) {
if (!out)


Loading…
Cancel
Save