xyarray.c 647 B

12345678910111213141516171819202122232425262728293031323334
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include "xyarray.h"
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <linux/zalloc.h>
  6. struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
  7. {
  8. size_t row_size = ylen * entry_size;
  9. struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size);
  10. if (xy != NULL) {
  11. xy->entry_size = entry_size;
  12. xy->row_size = row_size;
  13. xy->entries = xlen * ylen;
  14. xy->max_x = xlen;
  15. xy->max_y = ylen;
  16. }
  17. return xy;
  18. }
  19. void xyarray__reset(struct xyarray *xy)
  20. {
  21. size_t n = xy->entries * xy->entry_size;
  22. memset(xy->contents, 0, n);
  23. }
  24. void xyarray__delete(struct xyarray *xy)
  25. {
  26. free(xy);
  27. }