1b6a0e2cdSRichard Lowe /* The meat of this file is a copy of the FreeBSD sys/link_set.h */
2b6a0e2cdSRichard Lowe /*
3b6a0e2cdSRichard Lowe  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4b6a0e2cdSRichard Lowe  *
5b6a0e2cdSRichard Lowe  * Copyright (c) 1999 John D. Polstra
6b6a0e2cdSRichard Lowe  * Copyright (c) 1999,2001 Peter Wemm <peter@FreeBSD.org>
7b6a0e2cdSRichard Lowe  * All rights reserved.
8b6a0e2cdSRichard Lowe  *
9b6a0e2cdSRichard Lowe  * Redistribution and use in source and binary forms, with or without
10b6a0e2cdSRichard Lowe  * modification, are permitted provided that the following conditions
11b6a0e2cdSRichard Lowe  * are met:
12b6a0e2cdSRichard Lowe  * 1. Redistributions of source code must retain the above copyright
13b6a0e2cdSRichard Lowe  *    notice, this list of conditions and the following disclaimer.
14b6a0e2cdSRichard Lowe  * 2. Redistributions in binary form must reproduce the above copyright
15b6a0e2cdSRichard Lowe  *    notice, this list of conditions and the following disclaimer in the
16b6a0e2cdSRichard Lowe  *    documentation and/or other materials provided with the distribution.
17b6a0e2cdSRichard Lowe  *
18b6a0e2cdSRichard Lowe  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19b6a0e2cdSRichard Lowe  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20b6a0e2cdSRichard Lowe  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21b6a0e2cdSRichard Lowe  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22b6a0e2cdSRichard Lowe  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23b6a0e2cdSRichard Lowe  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24b6a0e2cdSRichard Lowe  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25b6a0e2cdSRichard Lowe  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26b6a0e2cdSRichard Lowe  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27b6a0e2cdSRichard Lowe  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28b6a0e2cdSRichard Lowe  * SUCH DAMAGE.
29b6a0e2cdSRichard Lowe  *
30b6a0e2cdSRichard Lowe  * $FreeBSD$
31b6a0e2cdSRichard Lowe  */
32b6a0e2cdSRichard Lowe 
33b6a0e2cdSRichard Lowe #include <stdio.h>
34*d56b5f9fSToomas Soome #include <sys/linker_set.h>
35b6a0e2cdSRichard Lowe 
36b6a0e2cdSRichard Lowe struct foo {
37b6a0e2cdSRichard Lowe 	char buf[128];
38b6a0e2cdSRichard Lowe };
39b6a0e2cdSRichard Lowe 
40b6a0e2cdSRichard Lowe SET_DECLARE(foo, struct foo);
41b6a0e2cdSRichard Lowe 
42b6a0e2cdSRichard Lowe struct foo a = { "foo" };
43b6a0e2cdSRichard Lowe struct foo b = { "bar" };
44b6a0e2cdSRichard Lowe struct foo c = { "baz" };
45b6a0e2cdSRichard Lowe 
46*d56b5f9fSToomas Soome SET_ENTRY(foo, a);
47*d56b5f9fSToomas Soome SET_ENTRY(foo, b);
48*d56b5f9fSToomas Soome SET_ENTRY(foo, c);
49b6a0e2cdSRichard Lowe 
50b6a0e2cdSRichard Lowe int
main(int argc,char ** argv)51b6a0e2cdSRichard Lowe main(int __attribute__((unused)) argc, char __attribute__((unused)) **argv)
52b6a0e2cdSRichard Lowe {
53b6a0e2cdSRichard Lowe 	struct foo **c;
54b6a0e2cdSRichard Lowe 	int i = 0;
55b6a0e2cdSRichard Lowe 
56*d56b5f9fSToomas Soome 	printf("Set count: %d\n", (int)SET_COUNT(foo));
57b6a0e2cdSRichard Lowe 
58b6a0e2cdSRichard Lowe 
59b6a0e2cdSRichard Lowe 	printf("a: %s\n", ((struct foo *)__set_foo_sym_a)->buf);
60b6a0e2cdSRichard Lowe 	printf("b: %s\n", ((struct foo *)__set_foo_sym_b)->buf);
61b6a0e2cdSRichard Lowe 	printf("c: %s\n", ((struct foo *)__set_foo_sym_c)->buf);
62b6a0e2cdSRichard Lowe 
63b6a0e2cdSRichard Lowe 	printf("item(foo, 0): %s\n", SET_ITEM(foo, 0)->buf);
64b6a0e2cdSRichard Lowe 	printf("item(foo, 1): %s\n", SET_ITEM(foo, 1)->buf);
65b6a0e2cdSRichard Lowe 	printf("item(foo, 2): %s\n", SET_ITEM(foo, 2)->buf);
66b6a0e2cdSRichard Lowe 
67b6a0e2cdSRichard Lowe 	SET_FOREACH(c, foo) {
68b6a0e2cdSRichard Lowe 		printf("foo[%d]: %s\n", i, (*c)->buf);
69b6a0e2cdSRichard Lowe 		i++;
70b6a0e2cdSRichard Lowe 	}
7111eb14c0SRobert Mustacchi 
7211eb14c0SRobert Mustacchi 	return (0);
73b6a0e2cdSRichard Lowe }
74