blob: 86889ebc35145e30961dddc9ccf2603cae05dd78 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -02002#include "xyarray.h"
Arnaldo Carvalho de Melo72f7c4d2017-04-19 19:06:30 -03003#include <stdlib.h>
4#include <string.h>
Arnaldo Carvalho de Melo7f7c5362019-07-04 11:32:27 -03005#include <linux/zalloc.h>
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -02006
7struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
8{
9 size_t row_size = ylen * entry_size;
10 struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size);
11
12 if (xy != NULL) {
13 xy->entry_size = entry_size;
14 xy->row_size = row_size;
Jiri Olsab45f65e2015-06-14 10:19:16 +020015 xy->entries = xlen * ylen;
Andi Kleend74be472017-08-11 16:26:16 -070016 xy->max_x = xlen;
17 xy->max_y = ylen;
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020018 }
19
20 return xy;
21}
22
Jiri Olsab45f65e2015-06-14 10:19:16 +020023void xyarray__reset(struct xyarray *xy)
24{
25 size_t n = xy->entries * xy->entry_size;
26
27 memset(xy->contents, 0, n);
28}
29
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020030void xyarray__delete(struct xyarray *xy)
31{
32 free(xy);
33}