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