|
Revision 371
(checked in by ben, 7 years ago)
|
Make sure dmalloc happens last.
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
#include <openpgpsdk/lists.h> |
|---|
| 8 |
|
|---|
| 9 |
#include <stdlib.h> |
|---|
| 10 |
|
|---|
| 11 |
#include <openpgpsdk/final.h> |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
void ops_ulong_list_init(ops_ulong_list_t *list) |
|---|
| 18 |
{ |
|---|
| 19 |
list->size=0; |
|---|
| 20 |
list->used=0; |
|---|
| 21 |
list->ulongs=NULL; |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
void ops_ulong_list_free(ops_ulong_list_t *list) |
|---|
| 30 |
{ |
|---|
| 31 |
if (list->ulongs) |
|---|
| 32 |
free(list->ulongs); |
|---|
| 33 |
ops_ulong_list_init(list); |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
static unsigned int ops_ulong_list_resize(ops_ulong_list_t *list) |
|---|
| 47 |
{ |
|---|
| 48 |
|
|---|
| 49 |
int newsize=0; |
|---|
| 50 |
|
|---|
| 51 |
newsize=list->size*2 + 1; |
|---|
| 52 |
list->ulongs=realloc(list->ulongs,newsize*sizeof *list->ulongs); |
|---|
| 53 |
if (list->ulongs) |
|---|
| 54 |
{ |
|---|
| 55 |
list->size=newsize; |
|---|
| 56 |
return 1; |
|---|
| 57 |
} |
|---|
| 58 |
else |
|---|
| 59 |
{ |
|---|
| 60 |
|
|---|
| 61 |
return 0; |
|---|
| 62 |
} |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
unsigned int ops_ulong_list_add(ops_ulong_list_t *list, unsigned long *ulong) |
|---|
| 74 |
{ |
|---|
| 75 |
if (list->size==list->used) |
|---|
| 76 |
if (!ops_ulong_list_resize(list)) |
|---|
| 77 |
return 0; |
|---|
| 78 |
|
|---|
| 79 |
list->ulongs[list->used]=*ulong; |
|---|
| 80 |
list->used++; |
|---|
| 81 |
return 1; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|