xref: /illumos-gate/usr/src/test/tz-tests/tests/tzlist.c (revision 4224453d626325281f3fcd656e646f681b9eca8b)
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 2025 Oxide Computer Company
14  */
15 
16 /*
17  * Use libzoneinfo to print a list of timezones for additional inspection. This
18  * is paired with some of the DTrace script wrappers.
19  */
20 
21 #include <stdio.h>
22 #include <err.h>
23 #include <libzoneinfo.h>
24 #include <stdlib.h>
25 #include <sys/debug.h>
26 
27 int
28 main(void)
29 {
30 	struct tz_continent *conts;
31 
32 	if (get_tz_continents(&conts) < 0) {
33 		err(EXIT_FAILURE, "failed to get continent list");
34 	}
35 
36 	for (struct tz_continent *ctnt = conts; ctnt != NULL;
37 	    ctnt = ctnt->ctnt_next) {
38 		struct tz_country *countries;
39 
40 		if (get_tz_countries(&countries, ctnt) < 0) {
41 			err(EXIT_FAILURE, "failed to get countries for %s",
42 			    ctnt->ctnt_name);
43 		}
44 
45 		for (struct tz_country *ctry = countries; ctry != NULL;
46 		    ctry = ctry->ctry_next) {
47 			struct tz_timezone *zones;
48 
49 			if (get_timezones_by_country(&zones, ctry) < 0) {
50 				err(EXIT_FAILURE, "failed to get timezones for "
51 				    "%s/%s", ctnt->ctnt_name, ctry->ctry_code);
52 			}
53 
54 			for (struct tz_timezone *tz = zones; tz != NULL;
55 			    tz = tz->tz_next) {
56 				(void) printf("%s\n", tz->tz_name);
57 			}
58 
59 			VERIFY0(free_timezones(zones));
60 		}
61 
62 		VERIFY0(free_tz_countries(countries));
63 	}
64 
65 	VERIFY0(free_tz_continents(conts));
66 	return (0);
67 }
68