This helper allows to copy one char into another.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
int kmscon_char_dup(struct kmscon_char **out, const struct kmscon_char *orig);
void kmscon_char_free(struct kmscon_char *ch);
+int kmscon_char_set(struct kmscon_char *ch, const struct kmscon_char *orig);
int kmscon_char_set_u8(struct kmscon_char *ch, const char *str, size_t len);
const char *kmscon_char_get_u8(const struct kmscon_char *ch);
size_t kmscon_char_get_len(const struct kmscon_char *ch);
free(ch);
}
+int kmscon_char_set(struct kmscon_char *ch, const struct kmscon_char *orig)
+{
+ char *buf;
+
+ if (!ch || !orig)
+ return -EINVAL;
+
+ if (ch->size < orig->len) {
+ buf = realloc(ch->buf, orig->len);
+ if (!buf)
+ return -ENOMEM;
+ ch->buf = buf;
+ ch->size = orig->len;
+ }
+
+ memcpy(ch->buf, orig->buf, orig->len);
+ ch->len = orig->len;
+
+ return 0;
+}
+
int kmscon_char_set_u8(struct kmscon_char *ch, const char *str, size_t len)
{
char *buf;