gdb: Remove inappropriate comments
[binutils-gdb.git] / libctf / testsuite / libctf-lookup / enum-symbol.c
blob1244c9004345bf901a35d4544a9d67d8ba70f5f0
1 #include "config.h"
2 #include <ctf-api.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
7 int
8 main (int argc, char *argv[])
10 ctf_archive_t *ctf;
11 ctf_dict_t *fp, *tmp_fp;
12 int err;
13 ctf_id_t type, tmp;
14 ctf_next_t *i = NULL;
15 const char *name;
16 int val;
18 if (argc != 2)
20 fprintf (stderr, "Syntax: %s PROGRAM\n", argv[0]);
21 exit(1);
24 if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL)
25 goto open_err;
27 /* Fish out the enumerator, then fish out all its enumerand/value pairs. */
29 if ((fp = ctf_arc_lookup_symbol_name (ctf, "primary1", &type, &err)) == NULL)
30 goto sym_err;
32 while ((name = ctf_enum_next (fp, type, &i, &val)) != NULL)
34 printf ("%s has value %i\n", name, val);
36 if (ctf_errno (fp) != ECTF_NEXT_END)
37 goto nerr;
39 /* Fish it out again to check the caching layer. */
40 if (((tmp_fp = ctf_arc_lookup_symbol_name (ctf, "primary1", &tmp, &err)) != fp)
41 || (tmp != type))
42 goto sym_cache_err;
44 ctf_dict_close (tmp_fp);
45 ctf_dict_close (fp);
46 ctf_close (ctf);
48 return 0;
50 open_err:
51 fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err));
52 return 1;
53 sym_err:
54 fprintf (stderr, "%s: Symbol lookup error: %s\n", argv[0], ctf_errmsg (err));
55 return 1;
56 sym_cache_err:
57 fprintf (stderr, "%s: Symbol re-lookup error (caching bug): %s\n", argv[0],
58 ctf_errmsg (err));
59 return 1;
60 nerr:
61 fprintf (stderr, "iteration failed: %s\n", ctf_errmsg (ctf_errno (fp)));
62 return 1;