aboutsummaryrefslogtreecommitdiffstats
path: root/libterminput_unmarshal_keypress__.c
blob: bd67e1ef564e35cfe2442825a0b811594e3f77ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* See LICENSE file for copyright and license details. */
#include "common.h"


int
libterminput_unmarshal_keypress__(struct libterminput_unmarshaller *how, struct libterminput_keypress *what)
{
	what->type = LIBTERMINPUT_KEYPRESS;
	if (how->load(how, &what->key, sizeof(what->key)) ||
	    how->load(how, &what->times, sizeof(what->times)) ||
	    how->load(how, &what->mods, sizeof(what->mods)))
		return -1;
	if ((uintmax_t)what->key > (uintmax_t)LIBTERMINPUT_LAST_KEY__) {
		errno = EINVAL;
		return -1;
	}
	if (what->key == LIBTERMINPUT_SYMBOL) {
		return how->load(how, what->symbol, sizeof(what->symbol));
	} else {
		memset(what->symbol, 0, sizeof(what->symbol));
		return 0;
	}
}