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:
David Herrmann 2011-11-26 15:27:10 +01:00
parent f66f1f5798
commit a12cf0aa7f
2 changed files with 28 additions and 0 deletions

View File

@ -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);

View File

@ -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)