xref: /illumos-gate/usr/src/head/tzfile.h (revision 6241235fe42e3c5c44d42933a0d41c38bd208c5c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 #ifndef _TZFILE_H
31 #define	_TZFILE_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 /*
36  * A part of this file comes from public domain source, so
37  * clarified as of June 5, 1996 by Arthur David Olson
38  * (arthur_david_olson@nih.gov).
39  */
40 
41 #include <sys/types.h>
42 
43 /*
44  * WARNING:
45  * The interfaces defined in this header file are for Sun private use only.
46  * The contents of this file are subject to change without notice for the
47  * future releases.
48  */
49 
50 /* For further information, see ctime(3C) and zic(1M) man pages. */
51 
52 /*
53  * This file is in the public domain, so clarified as of
54  * June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov).
55  */
56 
57 /*
58  * This header is for use ONLY with the time conversion code.
59  * There is no guarantee that it will remain unchanged,
60  * or that it will remain at all.
61  * Do NOT copy it to any system include directory.
62  * Thank you!
63  */
64 
65 /* static char	tzfilehid[] = "@(#)tzfile.h	7.17"; */
66 
67 /*
68  * Note: Despite warnings from the authors of this code, Solaris has
69  * placed this header file in the system include directory.  This was
70  * probably done in order to build both zic and zdump which are in
71  * separate source directories, but both use this file.
72  */
73 
74 #ifdef	__cplusplus
75 extern "C" {
76 #endif
77 
78 /*
79  * Information about time zone files.
80  */
81 
82 #ifndef TZDIR
83 #define	TZDIR	"/usr/share/lib/zoneinfo" /* Time zone object file directory */
84 #endif /* !defined TZDIR */
85 
86 #ifndef TZDEFAULT
87 #define	TZDEFAULT	"localtime"
88 #endif /* !defined TZDEFAULT */
89 
90 #ifndef TZDEFRULES
91 #define	TZDEFRULES	"posixrules"
92 #endif /* !defined TZDEFRULES */
93 
94 /*
95  * Each file begins with. . .
96  */
97 
98 #define	TZ_MAGIC	"TZif"
99 
100 struct tzhead {
101 	char	tzh_magic[4];		/* TZ_MAGIC */
102 	char	tzh_reserved[16];	/* reserved for future use */
103 	char	tzh_ttisgmtcnt[4];	/* coded number of trans. time flags */
104 	char	tzh_ttisstdcnt[4];	/* coded number of trans. time flags */
105 	char	tzh_leapcnt[4];		/* coded number of leap seconds */
106 	char	tzh_timecnt[4];		/* coded number of transition times */
107 	char	tzh_typecnt[4];		/* coded number of local time types */
108 	char	tzh_charcnt[4];		/* coded number of abbr. chars */
109 };
110 
111 /*
112  * . . .followed by. . .
113  *
114  *	tzh_timecnt (char [4])s		coded transition times a la time(2)
115  *	tzh_timecnt (unsigned char)s	types of local time starting at above
116  *	tzh_typecnt repetitions of
117  *		one (char [4])		coded UTC offset in seconds
118  *		one (unsigned char)	used to set tm_isdst
119  *		one (unsigned char)	that's an abbreviation list index
120  *	tzh_charcnt (char)s		'\0'-terminated zone abbreviations
121  *	tzh_leapcnt repetitions of
122  *		one (char [4])		coded leap second transition times
123  *		one (char [4])		total correction after above
124  *	tzh_ttisstdcnt (char)s		indexed by type; if TRUE, transition
125  *					time is standard time, if FALSE,
126  *					transition time is wall clock time
127  *					if absent, transition times are
128  *					assumed to be wall clock time
129  *	tzh_ttisgmtcnt (char)s		indexed by type; if TRUE, transition
130  *					time is UTC, if FALSE,
131  *					transition time is local time
132  *					if absent, transition times are
133  *					assumed to be local time
134  */
135 
136 /*
137  * In the current implementation, "tzset()" refuses to deal with files that
138  * exceed any of the limits below.
139  */
140 
141 #ifndef TZ_MAX_TIMES
142 /*
143  * The TZ_MAX_TIMES value below is enough to handle a bit more than a
144  * year's worth of solar time (corrected daily to the nearest second) or
145  * 138 years of Pacific Presidential Election time
146  * (where there are three time zone transitions every fourth year).
147  */
148 #define	TZ_MAX_TIMES	370
149 #endif /* !defined TZ_MAX_TIMES */
150 
151 #ifndef TZ_MAX_TYPES
152 #ifndef NOSOLAR
153 #define	TZ_MAX_TYPES	256 /* Limited by what (unsigned char)'s can hold */
154 #endif /* !defined NOSOLAR */
155 #ifdef NOSOLAR
156 /*
157  * Must be at least 14 for Europe/Riga as of Jan 12 1995,
158  * as noted by Earl Chew <earl@hpato.aus.hp.com>.
159  */
160 #define	TZ_MAX_TYPES	20	/* Maximum number of local time types */
161 #endif /* !defined NOSOLAR */
162 #endif /* !defined TZ_MAX_TYPES */
163 
164 #ifndef TZ_MAX_CHARS
165 #define	TZ_MAX_CHARS	50	/* Maximum number of abbreviation characters */
166 				/* (limited by what unsigned chars can hold) */
167 #endif /* !defined TZ_MAX_CHARS */
168 
169 #ifndef TZ_MAX_LEAPS
170 #define	TZ_MAX_LEAPS	50	/* Maximum number of leap second corrections */
171 #endif /* !defined TZ_MAX_LEAPS */
172 
173 #define	SECSPERMIN	60
174 #define	MINSPERHOUR	60
175 #define	HOURSPERDAY	24
176 #define	DAYSPERWEEK	7
177 #define	DAYSPERNYEAR	365
178 #define	DAYSPERLYEAR	366
179 #define	SECSPERHOUR	(SECSPERMIN * MINSPERHOUR)
180 #define	SECSPERDAY	((time_t)SECSPERHOUR * HOURSPERDAY)
181 #define	MONSPERYEAR	12
182 
183 #define	TM_SUNDAY	0
184 #define	TM_MONDAY	1
185 #define	TM_TUESDAY	2
186 #define	TM_WEDNESDAY	3
187 #define	TM_THURSDAY	4
188 #define	TM_FRIDAY	5
189 #define	TM_SATURDAY	6
190 
191 #define	TM_JANUARY	0
192 #define	TM_FEBRUARY	1
193 #define	TM_MARCH	2
194 #define	TM_APRIL	3
195 #define	TM_MAY		4
196 #define	TM_JUNE		5
197 #define	TM_JULY		6
198 #define	TM_AUGUST	7
199 #define	TM_SEPTEMBER	8
200 #define	TM_OCTOBER	9
201 #define	TM_NOVEMBER	10
202 #define	TM_DECEMBER	11
203 
204 #define	TM_YEAR_BASE	1900
205 
206 #define	EPOCH_YEAR	1970
207 #define	EPOCH_WDAY	TM_THURSDAY
208 
209 #define	isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
210 
211 #ifndef USG
212 
213 /*
214  * Use of the underscored variants may cause problems if you move your code to
215  * certain System-V-based systems; for maximum portability, use the
216  * underscore-free variants.  The underscored variants are provided for
217  * backward compatibility only; they may disappear from future versions of
218  * this file.
219  */
220 
221 #define	SECS_PER_MIN	SECSPERMIN
222 #define	MINS_PER_HOUR	MINSPERHOUR
223 #define	HOURS_PER_DAY	HOURSPERDAY
224 #define	DAYS_PER_WEEK	DAYSPERWEEK
225 #define	DAYS_PER_NYEAR	DAYSPERNYEAR
226 #define	DAYS_PER_LYEAR	DAYSPERLYEAR
227 #define	SECS_PER_HOUR	SECSPERHOUR
228 #define	SECS_PER_DAY	SECSPERDAY
229 #define	MONS_PER_YEAR	MONSPERYEAR
230 
231 #endif /* !defined USG */
232 
233 /*
234  * Since everything in isleap is modulo 400 (or a factor of 400), we know that
235  *	isleap(y) == isleap(y % 400)
236  * and so
237  *	isleap(a + b) == isleap((a + b) % 400)
238  * or
239  *	isleap(a + b) == isleap(a % 400 + b % 400)
240  * This is true even if % means modulo rather than Fortran remainder
241  * (which is allowed by C89 but not C99).
242  * We use this to avoid addition overflow problems.
243  */
244 
245 #define	isleap_sum(a, b)	isleap((a) % 400 + (b) % 400)
246 
247 #ifdef	__cplusplus
248 }
249 #endif
250 
251 #endif	/* _TZFILE_H */
252