about summary refs log tree commit diff stats
path: root/gemtext_list.c
blob: f050f67025b40338dec9f4c93d608bb50d1da3f0 (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
24
25
#include <stdlib.h>

#include "gemtext.h"

struct gemtext **
gemtext_list_append(struct gemtext **list, struct gemtext *item)
{
	int nitems;
	struct gemtext **ret;

	if (list != NULL) {
		for (nitems = 0; list[nitems] != NULL; nitems++); /* watch out */
		nitems += 2; /* one for new item, one for NULL */
	} else {
		nitems = 2;
	}

	ret = realloc(list, sizeof(*list)*nitems);
	if (ret == NULL)
		return NULL;
	ret[nitems-2] = item;
	ret[nitems-1] = NULL;

	return ret;
}