diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2020-12-01 13:33:34 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2020-12-01 13:33:34 +0100 |
commit | c8bf38e5fb717d40635a2a89b22ed71b0de4266b (patch) | |
tree | 63751b2f5497c6f99e1c6a78f23a8e6e5c49833f /tests/test52.c |
Squashed 'dependencies/uthash/' content from commit 8e67ced
git-subtree-dir: dependencies/uthash
git-subtree-split: 8e67ced1d1c5bd8141c542a22630e6de78aa6b90
Diffstat (limited to 'tests/test52.c')
-rw-r--r-- | tests/test52.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test52.c b/tests/test52.c new file mode 100644 index 000000000..3de12e40a --- /dev/null +++ b/tests/test52.c @@ -0,0 +1,48 @@ +#include <stdio.h> +#include <stdlib.h> +#include "utarray.h" + +typedef struct { + int a; + char *s; +} intchar_t; + +static void intchar_copy(void *_dst, const void *_src) +{ + intchar_t *dst = (intchar_t*)_dst; + const intchar_t *src = (const intchar_t*)_src; + dst->a = src->a; + dst->s = (src->s != NULL) ? strdup(src->s) : NULL; +} + +static void intchar_dtor(void *_elt) +{ + intchar_t *elt = (intchar_t*)_elt; + if (elt->s != NULL) { + free(elt->s); + } +} + +int main() +{ + UT_array *intchars; + intchar_t ic, *p; + UT_icd intchar_icd = {sizeof(intchar_t), NULL, intchar_copy, intchar_dtor}; + utarray_new(intchars, &intchar_icd); + + ic.a=1; + ic.s=(char*)"hello"; + utarray_push_back(intchars, &ic); + ic.a=2; + ic.s=(char*)"world"; + utarray_push_back(intchars, &ic); + + p=NULL; + while( (p=(intchar_t*)utarray_next(intchars,p)) != NULL ) { + printf("%d %s\n", p->a, (p->s != NULL) ? p->s : "null"); + } + + utarray_free(intchars); + return 0; +} + |