Add kmscon_char_set() helper
This helper allows to copy one char into another. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
0cf9a7a03c
commit
798276dea9
@ -28,6 +28,7 @@ int kmscon_char_new(struct kmscon_char **out);
|
||||
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);
|
||||
|
@ -132,6 +132,27 @@ void kmscon_char_free(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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user