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