From c8bf38e5fb717d40635a2a89b22ed71b0de4266b Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Tue, 1 Dec 2020 13:33:34 +0100 Subject: Squashed 'dependencies/uthash/' content from commit 8e67ced git-subtree-dir: dependencies/uthash git-subtree-split: 8e67ced1d1c5bd8141c542a22630e6de78aa6b90 --- tests/test52.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/test52.c (limited to 'tests/test52.c') 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 +#include +#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; +} + -- cgit v1.2.3