xref: /titanic_44/usr/src/head/time.h (revision ae115bc77f6fcde83175c75b4206dc2e50747966)
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 /*	Copyright (c) 1988 AT&T	*/
22 /*	  All Rights Reserved  	*/
23 
24 
25 /*
26  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 #ifndef _TIME_H
31 #define	_TIME_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.18 */
34 
35 #include <sys/feature_tests.h>
36 #include <iso/time_iso.h>
37 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
38 	(_POSIX_C_SOURCE > 2) || defined(__EXTENSIONS__)
39 #include <sys/types.h>
40 #include <sys/time_impl.h>
41 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) ... */
42 
43 /*
44  * Allow global visibility for symbols defined in
45  * C++ "std" namespace in <iso/time_iso.h>.
46  */
47 #if __cplusplus >= 199711L
48 using std::size_t;
49 using std::clock_t;
50 using std::time_t;
51 using std::tm;
52 using std::asctime;
53 using std::clock;
54 using std::ctime;
55 using std::difftime;
56 using std::gmtime;
57 using std::localtime;
58 using std::mktime;
59 using std::time;
60 using std::strftime;
61 #endif
62 
63 #ifdef	__cplusplus
64 extern "C" {
65 #endif
66 
67 #ifndef _CLOCKID_T
68 #define	_CLOCKID_T
69 typedef int	clockid_t;
70 #endif
71 
72 #ifndef _TIMER_T
73 #define	_TIMER_T
74 typedef int	timer_t;
75 #endif
76 
77 #if defined(__STDC__)
78 
79 #if defined(__EXTENSIONS__) || \
80 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
81 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
82 extern struct tm *gmtime_r(const time_t *_RESTRICT_KYWD,
83 			struct tm *_RESTRICT_KYWD);
84 extern struct tm *localtime_r(const time_t *_RESTRICT_KYWD,
85 			struct tm *_RESTRICT_KYWD);
86 #endif
87 
88 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
89 	defined(_XPG4) || defined(__EXTENSIONS__)
90 
91 #ifdef _STRPTIME_DONTZERO
92 #ifdef __PRAGMA_REDEFINE_EXTNAME
93 #pragma	redefine_extname strptime __strptime_dontzero
94 #else	/* __PRAGMA_REDEFINE_EXTNAME */
95 extern char *__strptime_dontzero(const char *, const char *, struct tm *);
96 #define	strptime	__strptime_dontzero
97 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
98 #endif	/* _STRPTIME_DONTZERO */
99 
100 extern char *strptime(const char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
101 		struct tm *_RESTRICT_KYWD);
102 
103 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))... */
104 
105 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
106 	(_POSIX_C_SOURCE > 2) || defined(__EXTENSIONS__)
107 /*
108  * Neither X/Open nor POSIX allow the inclusion of <signal.h> for the
109  * definition of the sigevent structure.  Both require the inclusion
110  * of <signal.h> and <time.h> when using the timer_create() function.
111  * However, X/Open also specifies that the sigevent structure be defined
112  * in <time.h> as described in the header <signal.h>.  This prevents
113  * compiler warnings for applications that only include <time.h> and not
114  * also <signal.h>.  The sigval union and the sigevent structure is
115  * therefore defined both here and in <sys/siginfo.h> which gets included
116  * via inclusion of <signal.h>.
117  */
118 #ifndef	_SIGVAL
119 #define	_SIGVAL
120 union sigval {
121 	int	sival_int;	/* integer value */
122 	void	*sival_ptr;	/* pointer value */
123 };
124 #endif	/* _SIGVAL */
125 
126 #ifndef	_SIGEVENT
127 #define	_SIGEVENT
128 struct sigevent {
129 	int		sigev_notify;	/* notification mode */
130 	int		sigev_signo;	/* signal number */
131 	union sigval	sigev_value;	/* signal value */
132 	void		(*sigev_notify_function)(union sigval);
133 	pthread_attr_t	*sigev_notify_attributes;
134 	int		__sigev_pad2;
135 };
136 #endif	/* _SIGEVENT */
137 
138 extern int clock_getres(clockid_t, struct timespec *);
139 extern int clock_gettime(clockid_t, struct timespec *);
140 extern int clock_settime(clockid_t, const struct timespec *);
141 extern int timer_create(clockid_t, struct sigevent *_RESTRICT_KYWD,
142 		timer_t *_RESTRICT_KYWD);
143 extern int timer_delete(timer_t);
144 extern int timer_getoverrun(timer_t);
145 extern int timer_gettime(timer_t, struct itimerspec *);
146 extern int timer_settime(timer_t, int, const struct itimerspec *_RESTRICT_KYWD,
147 		struct itimerspec *_RESTRICT_KYWD);
148 
149 extern int nanosleep(const struct timespec *, struct timespec *);
150 extern int clock_nanosleep(clockid_t, int,
151 	const struct timespec *, struct timespec *);
152 
153 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))... */
154 
155 #if !defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX) || \
156 	defined(__EXTENSIONS__)
157 
158 extern void tzset(void);
159 extern char *tzname[2];
160 
161 /* CLK_TCK marked as LEGACY in SUSv2 and removed in SUSv3 */
162 #if !defined(_XPG6) || defined(__EXTENSIONS__)
163 #ifndef CLK_TCK
164 extern long _sysconf(int);	/* System Private interface to sysconf() */
165 #define	CLK_TCK	((clock_t)_sysconf(3))	/* clock ticks per second */
166 				/* 3 is _SC_CLK_TCK */
167 #endif
168 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
169 
170 #if (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
171 	defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
172 extern long timezone;
173 extern int daylight;
174 #endif
175 
176 #endif /* !defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX)... */
177 
178 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
179 	defined(__EXTENSIONS__)
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