xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/uctf/tst.chasestrings.c (revision 0245b61fd282e95735b173b8d95be0d6688163b4)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2013 (c) Joyent, Inc. All rights reserved.
14  */
15 
16 /*
17  * This test takes data from the current binary which is basically running in a
18  * loop between two functions and our goal is to have two unique types that they
19  * contain which we can print.
20  */
21 
22 #include <unistd.h>
23 
24 typedef struct zelda_info {
25 	char	*zi_gamename;
26 	int	zi_ndungeons;
27 	char	*zi_villain;
28 	int	zi_haszelda;
29 } zelda_info_t;
30 
31 static int
32 has_princess(zelda_info_t *z)
33 {
34 	return (z->zi_haszelda);
35 }
36 
37 static int
38 has_dungeons(zelda_info_t *z)
39 {
40 	return (z->zi_ndungeons != 0);
41 }
42 
43 static const char *
44 has_villain(zelda_info_t *z)
45 {
46 	return (z->zi_villain);
47 }
48 
49 int
50 main(void)
51 {
52 	zelda_info_t oot;
53 	zelda_info_t la;
54 	zelda_info_t lttp;
55 
56 	oot.zi_gamename = "Ocarina of Time";
57 	oot.zi_ndungeons = 10;
58 	oot.zi_villain = "Ganondorf";
59 	oot.zi_haszelda = 1;
60 
61 	la.zi_gamename = "Link's Awakening";
62 	la.zi_ndungeons = 9;
63 	la.zi_villain = "Nightmare";
64 	la.zi_haszelda = 0;
65 
66 	lttp.zi_gamename = "A Link to the Past";
67 	lttp.zi_ndungeons = 12;
68 	lttp.zi_villain = "Ganon";
69 	lttp.zi_haszelda = 1;
70 
71 	for (;;) {
72 		(void) has_princess(&oot);
73 		(void) has_dungeons(&la);
74 		(void) has_villain(&lttp);
75 		sleep(1);
76 	}
77 
78 	return (0);
79 }
80