about summary refs log tree commit diff
path: root/misc/tst-hsearch.c
blob: d390f1dcf3545502bdd4fc10542a62d725b16a76 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <search.h>
#include <stdio.h>

static int
do_test (void)
{
  int a = 1;
  int b = 2;
  ENTRY i;
  ENTRY *e;

  if (hcreate (20) == 0)
    {
      puts ("hcreate failed");
      return 1;
    }

  i.key = (char *) "one";
  i.data = &a;
  if (hsearch (i, ENTER) == NULL)
    return 1;

  i.key = (char *) "one";
  i.data = &b;
  e = hsearch (i, ENTER);
  printf ("e.data = %d\n", *(int *) e->data);
  if (*(int *) e->data != 1)
    return 1;

  return 0;
}

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"