Line data Source code
1 : #include "../../../burp.h"
2 : #include "../../../alloc.h"
3 : #include "scores.h"
4 :
5 2 : struct scores *scores_alloc(void)
6 : {
7 2 : return (struct scores *)calloc_w(1, sizeof(struct scores), __func__);
8 : }
9 :
10 : static void scores_free_content(struct scores *scores)
11 : {
12 2 : if(!scores) return;
13 2 : free_v((void **)&scores->scores);
14 : }
15 :
16 2 : void scores_free(struct scores **scores)
17 : {
18 4 : if(!scores) return;
19 2 : scores_free_content(*scores);
20 2 : free_v((void **)scores);
21 : }
22 :
23 : // Return -1 or error, 0 on OK.
24 17 : int scores_grow(struct scores *scores, size_t count)
25 : {
26 17 : if(!scores || !count) return 0;
27 14 : scores->size=count;
28 14 : if(!(scores->scores=(uint16_t *)realloc_w(scores->scores,
29 14 : sizeof(uint16_t)*scores->size, __func__)))
30 : return -1;
31 13 : return 0;
32 : }
33 :
34 16 : void scores_reset(struct scores *scores)
35 : {
36 16 : if(!scores
37 14 : || !scores->scores
38 13 : || !scores->size)
39 16 : return;
40 13 : memset(scores->scores, 0, sizeof(scores->scores[0])*scores->size);
41 : }
|