aboutsummaryrefslogtreecommitdiff
path: root/tests/test20.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test20.c')
-rw-r--r--tests/test20.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test20.c b/tests/test20.c
new file mode 100644
index 000000000..9ac01f0ac
--- /dev/null
+++ b/tests/test20.c
@@ -0,0 +1,34 @@
+#include <string.h> /* memcpy */
+#include <stdlib.h> /* malloc */
+#include <stdio.h> /* printf */
+#include "uthash.h"
+
+struct my_struct {
+ char bkey[5]; /* "binary" key */
+ int data;
+ UT_hash_handle hh;
+};
+
+int main()
+{
+ struct my_struct *s, *t, *bins = NULL;
+ char binary[5] = {'\3','\1','\4','\1','\6'};
+
+ /* allocate our structure. initialize to some values */
+ s = (struct my_struct*)calloc(1UL,sizeof(struct my_struct));
+ if (s == NULL) {
+ exit(-1);
+ }
+ memcpy(s->bkey, binary, sizeof(binary));
+
+ /* add to hash table using general macro */
+ HASH_ADD( hh, bins, bkey, sizeof(binary), s);
+
+ /* look up the structure we just added */
+ HASH_FIND( hh, bins, binary, sizeof(binary), t );
+
+ if (t != NULL) {
+ printf("found\n");
+ }
+ return 0;
+}