1*4b169a6bSchristos #include <ctf-api.h>
2*4b169a6bSchristos #include <stdio.h>
3*4b169a6bSchristos #include <stdlib.h>
4*4b169a6bSchristos
5*4b169a6bSchristos int
main(int argc,char * argv[])6*4b169a6bSchristos main (int argc, char *argv[])
7*4b169a6bSchristos {
8*4b169a6bSchristos ctf_dict_t *fp;
9*4b169a6bSchristos ctf_archive_t *ctf;
10*4b169a6bSchristos ctf_next_t *i = NULL;
11*4b169a6bSchristos ctf_id_t type;
12*4b169a6bSchristos const char *arcname;
13*4b169a6bSchristos int err;
14*4b169a6bSchristos
15*4b169a6bSchristos if (argc != 2)
16*4b169a6bSchristos {
17*4b169a6bSchristos fprintf (stderr, "Syntax: %s PROGRAM\n", argv[0]);
18*4b169a6bSchristos exit(1);
19*4b169a6bSchristos }
20*4b169a6bSchristos
21*4b169a6bSchristos if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL)
22*4b169a6bSchristos goto open_err;
23*4b169a6bSchristos
24*4b169a6bSchristos /* Make sure we can look up a_t * by name in all non-parent dicts, even though
25*4b169a6bSchristos the a_t * and the type it points to are in distinct dicts; make sure we
26*4b169a6bSchristos cannot look up b_t *. */
27*4b169a6bSchristos
28*4b169a6bSchristos while ((fp = ctf_archive_next (ctf, &i, &arcname, 1, &err)) != NULL)
29*4b169a6bSchristos {
30*4b169a6bSchristos if ((type = ctf_lookup_by_name (fp, "a_t *")) == CTF_ERR)
31*4b169a6bSchristos goto err;
32*4b169a6bSchristos
33*4b169a6bSchristos if ((ctf_lookup_by_name (fp, "b_t *")) != CTF_ERR ||
34*4b169a6bSchristos ctf_errno (fp) != ECTF_NOTYPE)
35*4b169a6bSchristos goto noerr;
36*4b169a6bSchristos
37*4b169a6bSchristos if (ctf_type_reference (fp, type) == CTF_ERR)
38*4b169a6bSchristos goto err;
39*4b169a6bSchristos
40*4b169a6bSchristos printf ("%s: a_t * points to a type of kind %i\n", arcname,
41*4b169a6bSchristos ctf_type_kind (fp, ctf_type_reference (fp, type)));
42*4b169a6bSchristos
43*4b169a6bSchristos ctf_dict_close (fp);
44*4b169a6bSchristos }
45*4b169a6bSchristos if (err != ECTF_NEXT_END)
46*4b169a6bSchristos goto open_err;
47*4b169a6bSchristos
48*4b169a6bSchristos ctf_close (ctf);
49*4b169a6bSchristos
50*4b169a6bSchristos return 0;
51*4b169a6bSchristos
52*4b169a6bSchristos open_err:
53*4b169a6bSchristos fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err));
54*4b169a6bSchristos return 1;
55*4b169a6bSchristos err:
56*4b169a6bSchristos fprintf (stderr, "Lookup failed in %s: %s\n", arcname, ctf_errmsg (ctf_errno (fp)));
57*4b169a6bSchristos return 1;
58*4b169a6bSchristos noerr:
59*4b169a6bSchristos fprintf (stderr, "Lookup unexpectedly succeeded in %s\n", arcname);
60*4b169a6bSchristos return 1;
61*4b169a6bSchristos }
62