/* Returns 1 if successful, -EINVAL if m is NULL, or -ENOMEM if there is insufficient memory to add the menu item.  */
int menu_item_add(struct menu *m, char *item_key, void *item_data)
/* Returns 1 if successful, -EINVAL if m is NULL, or -ENOMEM if there is insufficient memory to add the menu item.  */
int menu_item_add(struct menu *m, char *item_key, void *item_data)
{
	struct menu_item *item;
	if (!m)
		return -EINVAL;
	item = menu_item_by_key(m, item_key);
	if (item) {
		item->data = item_data;
		return 1;
	}
	item = malloc(sizeof *item);
	if (!item)
		return -ENOMEM;
	item->key = strdup(item_key);
	if (!item->key) {
		free(item);
		return -ENOMEM;
	}
	item->data = item_data;
	list_add_tail(&item->list, &m->items);
	m->item_cnt++;
	return 1;
}