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