Add kmscon_char_dup()
Add helper function to duplicate a kmscon_char object. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
f66f1f5798
commit
a12cf0aa7f
@ -23,6 +23,7 @@ struct kmscon_console;
|
||||
/* single printable characters */
|
||||
|
||||
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_u8(struct kmscon_char *ch, const char *str, size_t len);
|
||||
|
@ -61,6 +61,33 @@ int kmscon_char_new(struct kmscon_char **out)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int kmscon_char_dup(struct kmscon_char **out, const struct kmscon_char *orig)
|
||||
{
|
||||
struct kmscon_char *ch;
|
||||
|
||||
if (!out || !orig)
|
||||
return -EINVAL;
|
||||
|
||||
ch = malloc(sizeof(*ch));
|
||||
if (!ch)
|
||||
return -ENOMEM;
|
||||
|
||||
memset(ch, 0, sizeof(*ch));
|
||||
|
||||
ch->len = orig->len;
|
||||
ch->size = orig->size;
|
||||
ch->buf = malloc(ch->size);
|
||||
if (!ch->buf) {
|
||||
free(ch);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(ch->buf, orig->buf, ch->size);
|
||||
|
||||
*out = ch;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kmscon_char_free(struct kmscon_char *ch)
|
||||
{
|
||||
if (!ch)
|
||||
|
Loading…
x
Reference in New Issue
Block a user