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