xref: /titanic_41/usr/src/head/time.h (revision 1d4b38e0077763e7c9b20768eacb841957e787bc)
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 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #ifndef _TIME_H
32 #define	_TIME_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.18 */
35 
36 #include <sys/feature_tests.h>
37 #include <iso/time_iso.h>
38 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
39 	(_POSIX_C_SOURCE > 2) || defined(__EXTENSIONS__)
40 #include <sys/types.h>
41 #include <sys/time_impl.h>
42 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) ... */
43 
44 /*
45  * Allow global visibility for symbols defined in
46  * C++ "std" namespace in <iso/time_iso.h>.
47  */
48 #if __cplusplus >= 199711L
49 using std::size_t;
50 using std::clock_t;
51 using std::time_t;
52 using std::tm;
53 using std::asctime;
54 using std::clock;
55 using std::ctime;
56 using std::difftime;
57 using std::gmtime;
58 using std::localtime;
59 using std::mktime;
60 using std::time;
61 using std::strftime;
62 #endif
63 
64 #ifdef	__cplusplus
65 extern "C" {
66 #endif
67 
68 #ifndef _CLOCKID_T
69 #define	_CLOCKID_T
70 typedef int	clockid_t;
71 #endif
72 
73 #ifndef _TIMER_T
74 #define	_TIMER_T
75 typedef int	timer_t;
76 #endif
77 
78 #if defined(__STDC__)
79 
80 #if defined(__EXTENSIONS__) || \
81 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
82 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
83 extern struct tm *gmtime_r(const time_t *_RESTRICT_KYWD,
84 			struct tm *_RESTRICT_KYWD);
85 extern struct tm *localtime_r(const time_t *_RESTRICT_KYWD,
86 			struct tm *_RESTRICT_KYWD);
87 #endif
88 
89 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
90 	defined(_XPG4) || defined(__EXTENSIONS__)
91 
92 #ifdef _STRPTIME_DONTZERO
93 #ifdef __PRAGMA_REDEFINE_EXTNAME
94 #pragma	redefine_extname strptime __strptime_dontzero
95 #else	/* __PRAGMA_REDEFINE_EXTNAME */
96 extern char *__strptime_dontzero(const char *, const char *, struct tm *);
97 #define	strptime	__strptime_dontzero
98 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
99 #endif	/* _STRPTIME_DONTZERO */
100 
101 extern char *strptime(const char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
102 		struct tm *_RESTRICT_KYWD);
103 
104 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))... */
105 
106 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
107 	(_POSIX_C_SOURCE > 2) || defined(__EXTENSIONS__)
108 /*
109  * Neither X/Open nor POSIX allow the inclusion of <signal.h> for the
110  * definition of the sigevent structure.  Both require the inclusion
111  * of <signal.h> and <time.h> when using the timer_create() function.
112  * However, X/Open also specifies that the sigevent structure be defined
113  * in <time.h> as described in the header <signal.h>.  This prevents
114  * compiler warnings for applications that only include <time.h> and not
115  * also <signal.h>.  The sigval union and the sigevent structure is
116  * therefore defined both here and in <sys/siginfo.h> which gets included
117  * via inclusion of <signal.h>.
118  */
119 #ifndef	_SIGVAL
120 #define	_SIGVAL
121 union sigval {
122 	int	sival_int;	/* integer value */
123 	void	*sival_ptr;	/* pointer value */
124 };
125 #endif	/* _SIGVAL */
126 
127 #ifndef	_SIGEVENT
128 #define	_SIGEVENT
129 struct sigevent {
130 	int		sigev_notify;	/* notification mode */
131 	int		sigev_signo;	/* signal number */
132 	union sigval	sigev_value;	/* signal value */
133 	void		(*sigev_notify_function)(union sigval);
134 	pthread_attr_t	*sigev_notify_attributes;
135 	int		__sigev_pad2;
136 };
137 #endif	/* _SIGEVENT */
138 
139 extern int clock_getres(clockid_t, struct timespec *);
140 extern int clock_gettime(clockid_t, struct timespec *);
141 extern int clock_settime(clockid_t, const struct timespec *);
142 extern int timer_create(clockid_t, struct sigevent *_RESTRICT_KYWD,
143 		timer_t *_RESTRICT_KYWD);
144 extern int timer_delete(timer_t);
145 extern int timer_getoverrun(timer_t);
146 extern int timer_gettime(timer_t, struct itimerspec *);
147 extern int timer_settime(timer_t, int, const struct itimerspec *_RESTRICT_KYWD,
148 		struct itimerspec *_RESTRICT_KYWD);
149 
150 extern int nanosleep(const struct timespec *, struct timespec *);
151 extern int clock_nanosleep(clockid_t, int,
152 	const struct timespec *, struct timespec *);
153 
154 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))... */
155 
156 #if !defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX) || \
157 	defined(__EXTENSIONS__)
158 
159 extern void tzset(void);
160 extern char *tzname[2];
161 
162 /* CLK_TCK marked as LEGACY in SUSv2 and removed in SUSv3 */
163 #if !defined(_XPG6) || defined(__EXTENSIONS__)
164 #ifndef CLK_TCK
165 extern long _sysconf(int);	/* System Private interface to sysconf() */
166 #define	CLK_TCK	((clock_t)_sysconf(3))	/* clock ticks per second */
167 				/* 3 is _SC_CLK_TCK */
168 #endif
169 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
170 
171 #if (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
172 	defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
173 extern long timezone;
174 extern int daylight;
175 #endif
176 
177 #endif /* !defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX)... */
178 
179 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
180 extern int cftime(char *, char *, const time_t *);
181 extern int ascftime(char *, const char *, const struct tm *);
182 extern long altzone;
183 #endif
184 
185 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
186 	defined(_XPG4_2) || defined(__EXTENSIONS__)
187 extern struct tm *getdate(const char *);
188 #ifdef	_REENTRANT
189 #undef getdate_err
190 #define	getdate_err *(int *)_getdate_err_addr()
191 extern int *_getdate_err_addr(void);
192 #else
193 extern int getdate_err;
194 #endif /* _REENTRANT */
195 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))... */
196 
197 #else /* __STDC__ */
198 
199 extern int cftime(), ascftime();
200 extern void tzset();
201 
202 #ifdef _STRPTIME_DONTZERO
203 #ifdef __PRAGMA_REDEFINE_EXTNAME
204 #pragma	redefine_extname strptime	__strptime_dontzero
205 #else	/* __PRAGMA_REDEFINE_EXTNAME */
206 extern char *__strptime_dontzero();
207 #define	strptime	__strptime_dontzero
208 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
209 #endif	/* _STRPTIME_DONTZERO */
210 
211 extern char *strptime();
212 
213 #if defined(__EXTENSIONS__) || \
214 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
215 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
216 extern struct tm *gmtime_r();
217 extern struct tm *localtime_r();
218 #endif
219 
220 extern long timezone, altzone;
221 extern int daylight;
222 extern char *tzname[2];
223 
224 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
225 extern struct tm *getdate();
226 #ifdef	_REENTRANT
227 #undef getdate_err
228 #define	getdate_err *(int *)_getdate_err_addr()
229 extern int *_getdate_err_addr();
230 #else
231 extern int getdate_err;
232 #endif /* _REENTRANT */
233 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
234 
235 #endif	/* __STDC__ */
236 
237 /*
238  * ctime_r() & asctime_r() prototypes are defined here.
239  */
240 
241 /*
242  * Previous releases of Solaris, starting at 2.3, provided definitions of
243  * various functions as specified in POSIX.1c, Draft 6.  For some of these
244  * functions, the final POSIX 1003.1c standard had a different number of
245  * arguments and return values.
246  *
247  * The following segment of this header provides support for the standard
248  * interfaces while supporting applications written under earlier
249  * releases.  The application defines appropriate values of the feature
250  * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate
251  * whether it was written to expect the Draft 6 or standard versions of
252  * these interfaces, before including this header.  This header then
253  * provides a mapping from the source version of the interface to an
254  * appropriate binary interface.  Such mappings permit an application
255  * to be built from libraries and objects which have mixed expectations
256  * of the definitions of these functions.
257  *
258  * For applications using the Draft 6 definitions, the binary symbol is the
259  * same as the source symbol, and no explicit mapping is needed.  For the
260  * standard interface, the function func() is mapped to the binary symbol
261  * _posix_func().  The preferred mechanism for the remapping is a compiler
262  * #pragma.  If the compiler does not provide such a #pragma, the header file
263  * defines a static function func() which calls the _posix_func() version;
264  * this has to be done instead of #define since POSIX specifies that an
265  * application can #undef the symbol and still be bound to the correct
266  * implementation.  Unfortunately, the statics confuse lint so we fallback to
267  * #define in that case.
268  *
269  * NOTE: Support for the Draft 6 definitions is provided for compatibility
270  * only.  New applications/libraries should use the standard definitions.
271  */
272 
273 #if	defined(__EXTENSIONS__) || defined(_REENTRANT) || \
274 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
275 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
276 
277 #if	defined(__STDC__)
278 
279 #if	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
280 
281 #ifdef __PRAGMA_REDEFINE_EXTNAME
282 #pragma redefine_extname ctime_r __posix_ctime_r
283 #pragma redefine_extname asctime_r __posix_asctime_r
284 extern char *asctime_r(const struct tm *_RESTRICT_KYWD, char *_RESTRICT_KYWD);
285 extern char *ctime_r(const time_t *, char *);
286 #else  /* __PRAGMA_REDEFINE_EXTNAME */
287 
288 extern char *__posix_asctime_r(const struct tm *_RESTRICT_KYWD,
289     char *_RESTRICT_KYWD);
290 extern char *__posix_ctime_r(const time_t *, char *);
291 
292 #ifdef	__lint
293 
294 #define	ctime_r __posix_ctime_r
295 #define	asctime_r __posix_asctime_r
296 
297 #else	/* !__lint */
298 
299 static char *
300 asctime_r(const struct tm *_RESTRICT_KYWD __tm, char *_RESTRICT_KYWD __buf)
301 {
302 	return (__posix_asctime_r(__tm, __buf));
303 }
304 
305 static char *
306 ctime_r(const time_t *__time, char *__buf)
307 {
308 	return (__posix_ctime_r(__time, __buf));
309 }
310 
311 #endif /* !__lint */
312 #endif /* __PRAGMA_REDEFINE_EXTNAME */
313 
314 #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
315 
316 extern char *asctime_r(const struct tm *, char *, int);
317 extern char *ctime_r(const time_t *, char *, int);
318 
319 #endif  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
320 
321 #else  /* __STDC__ */
322 
323 #if	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
324 
325 #ifdef __PRAGMA_REDEFINE_EXTNAME
326 #pragma redefine_extname asctime_r __posix_asctime_r
327 #pragma redefine_extname ctime_r __posix_ctime_r
328 extern char *asctime_r();
329 extern char *ctime_r();
330 #else  /* __PRAGMA_REDEFINE_EXTNAME */
331 
332 extern char *__posix_asctime_r();
333 extern char *__posix_ctime_r();
334 
335 #ifdef	__lint
336 
337 #define	asctime_r __posix_asctime_r
338 #define	ctime_r __posix_ctime_r
339 
340 #else	/* !__lint */
341 
342 static char *
343 asctime_r(__tm, __buf)
344 	struct tm *__tm;
345 	char *__buf;
346 {
347 	return (__posix_asctime_r(__tm, __buf));
348 }
349 static char *
350 ctime_r(__time, __buf)
351 	time_t *__time;
352 	char *__buf;
353 {
354 	return (__posix_ctime_r(__time, __buf));
355 }
356 
357 #endif /* !__lint */
358 #endif /* __PRAGMA_REDEFINE_EXTNAME */
359 
360 #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
361 
362 extern char *asctime_r();
363 extern char *ctime_r();
364 
365 #endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
366 
367 #endif /* __STDC__ */
368 
369 #endif /* defined(__EXTENSIONS__) || defined(_REENTRANT)... */
370 
371 #ifdef	__cplusplus
372 }
373 #endif
374 
375 #endif	/* _TIME_H */
376