Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <internal/xyarray.h>
0003 #include <linux/zalloc.h>
0004 #include <stdlib.h>
0005 #include <string.h>
0006 
0007 struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
0008 {
0009     size_t row_size = ylen * entry_size;
0010     struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size);
0011 
0012     if (xy != NULL) {
0013         xy->entry_size = entry_size;
0014         xy->row_size   = row_size;
0015         xy->entries    = xlen * ylen;
0016         xy->max_x      = xlen;
0017         xy->max_y      = ylen;
0018     }
0019 
0020     return xy;
0021 }
0022 
0023 void xyarray__reset(struct xyarray *xy)
0024 {
0025     size_t n = xy->entries * xy->entry_size;
0026 
0027     memset(xy->contents, 0, n);
0028 }
0029 
0030 void xyarray__delete(struct xyarray *xy)
0031 {
0032     free(xy);
0033 }