xyarray.c 656 B

123456789101112131415161718192021222324252627282930313233
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <internal/xyarray.h>
  3. #include <linux/zalloc.h>
  4. #include <stdlib.h>
  5. #include <string.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. }