aboutsummaryrefslogtreecommitdiffstats
path: root/rtgrpblib_create_raster.c
blob: 89ebad65a3cce1bc0e6f5f78e3cf3b91c6ecf981 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


RASTER *
rtgrpblib_create_raster(size_t width, size_t height)
{
	RASTER *raster;

	if (!width || !height) {
		errno = EINVAL;
		return NULL;
	}

	if (width > (SIZE_MAX - offsetof(RASTER, cells)) / sizeof(*raster->cells) / height)
		goto enomem;
	raster = calloc(1, offsetof(RASTER, cells) + height * width * sizeof(*raster->cells));
	if (!raster) {
	enomem:
		errno = ENOMEM;
		return NULL;
	}

	raster->width = width;
	raster->height = height;
	raster->draftness = 0.5;
	return raster;
}


#else

int
main(void)
{
	return 0; /* TODO add test */
}

#endif