xref: /titanic_50/usr/src/head/time.h (revision f38cb554a534c6df738be3f4d23327e69888e634)
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  * Copyright 2010 Nexenta Systems, Inc.  Al rights reserved.
31  */
32 
33 #ifndef _TIME_H
34 #define	_TIME_H
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 	defined(__EXTENSIONS__)
181 extern time_t timegm(struct tm *);
182 extern int cftime(char *, char *, const time_t *);
183 extern int ascftime(char *, const char *, const struct tm *);
184 extern long altzone;
185 #endif
186 
187 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
188 	defined(_XPG4_2) || defined(__EXTENSIONS__)
189 extern struct tm *getdate(const char *);
190 #ifdef	_REENTRANT
191 #undef getdate_err
192 #define	getdate_err *(int *)_getdate_err_addr()
193 extern int *_getdate_err_addr(void);
194 #else
195 extern int getdate_err;
196 #endif /* _REENTRANT */
197 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))... */
198 
199 #else /* __STDC__ */
200 
201 extern int cftime(), ascftime();
202 extern void tzset();
203 extern time_t timegm();
204 
205 #ifdef _STRPTIME_DONTZERO
206 #ifdef __PRAGMA_REDEFINE_EXTNAME
207 #pragma	redefine_extname strptime	__strptime_dontzero
208 #else	/* __PRAGMA_REDEFINE_EXTNAME */
209 extern char *__strptime_dontzero();
210 #define	strptime	__strptime_dontzero
211 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
212 #endif	/* _STRPTIME_DONTZERO */
213 
214 extern char *strptime();
215 
216 #if defined(__EXTENSIONS__) || \
217 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
218 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT)
219 extern struct tm *gmtime_r();
220 extern struct tm *localtime_r();
221 #endif
222 
223 extern long timezone, altzone;
224 extern int daylight;
225 extern char *tzname[2];
226 
227 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
228 extern struct tm *getdate();
229 #ifdef	_REENTRANT
230 #undef getdate_err
231 #define	getdate_err *(int *)_getdate_err_addr()
232 extern int *_getdate_err_addr();
233 #else
234 extern int getdate_err;
235 #endif /* _REENTRANT */
236 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
237 
238 #endif	/* __STDC__ */
239 
240 /*
241  * ctime_r() & asctime_r() prototypes are defined here.
242  */
243 
244 /*
245  * Previous releases of Solaris, starting at 2.3, provided definitions of
246  * various functions as specified in POSIX.1c, Draft 6.  For some of these
247  * functions, the final POSIX 1003.1c standard had a different number of
248  * arguments and return values.
249  *
250  * The following segment of this header provides support for the standard
251  * interfaces while supporting applications written under earlier
252  * releases.  The application defines appropriate values of the feature
253  * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate
254  * whether it was written to expect the Draft 6 or standard versions of
255  * these interfaces, before including this header.  This header then
256  * provides a mapping from the source version of the interface to an
257  * appropriate binary interface.  Such mappings permit an application
258  * to be built from libraries and objects which have mixed expectations
259  * of the definitions of these functions.
260  *
261  * For applications using the Draft 6 definitions, the binary symbol is the
262  * same as the source symbol, and no explicit mapping is needed.  For the
263  * standard interface, the function func() is mapped to the binary symbol
264  * _posix_func().  The preferred mechanism for the remapping is a compiler
265  * #pragma.  If the compiler does not provide such a #pragma, the header file
266  * defines a static function func() which calls the _posix_func() version;
267  * this has to be done instead of #define since POSIX specifies that an
268  * application can #undef the symbol and still be bound to the correct
269  * implementation.  Unfortunately, the statics confuse lint so we fallback to
270  * #define in that case.
271  *
272  * NOTE: Support for the Draft 6 definitions is provided for compatibility
273  * only.  New applications/libraries should use the standard definitions.
274  */
275 
276 #if	defined(__EXTENSIONS__) || defined(_REENTRANT) || \
277 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
278 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
279 
280 #if	defined(__STDC__)
281 
282 #if	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
283 
284 #ifdef __PRAGMA_REDEFINE_EXTNAME
285 #pragma redefine_extname ctime_r __posix_ctime_r
286 #pragma redefine_extname asctime_r __posix_asctime_r
287 extern char *asctime_r(const struct tm *_RESTRICT_KYWD, char *_RESTRICT_KYWD);
288 extern char *ctime_r(const time_t *, char *);
289 #else  /* __PRAGMA_REDEFINE_EXTNAME */
290 
291 extern char *__posix_asctime_r(const struct tm *_RESTRICT_KYWD,
292     char *_RESTRICT_KYWD);
293 extern char *__posix_ctime_r(const time_t *, char *);
294 
295 #ifdef	__lint
296 
297 #define	ctime_r __posix_ctime_r
298 #define	asctime_r __posix_asctime_r
299 
300 #else	/* !__lint */
301 
302 static char *
303 asctime_r(const struct tm *_RESTRICT_KYWD __tm, char *_RESTRICT_KYWD __buf)
304 {
305 	return (__posix_asctime_r(__tm, __buf));
306 }
307 
308 static char *
309 ctime_r(const time_t *__time, char *__buf)
310 {
311 	return (__posix_ctime_r(__time, __buf));
312 }
313 
314 #endif /* !__lint */
315 #endif /* __PRAGMA_REDEFINE_EXTNAME */
316 
317 #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
318 
319 extern char *asctime_r(const struct tm *, char *, int);
320 extern char *ctime_r(const time_t *, char *, int);
321 
322 #endif  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
323 
324 #else  /* __STDC__ */
325 
326 #if	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
327 
328 #ifdef __PRAGMA_REDEFINE_EXTNAME
329 #pragma redefine_extname asctime_r __posix_asctime_r
330 #pragma redefine_extname ctime_r __posix_ctime_r
331 extern char *asctime_r();
332 extern char *ctime_r();
333 #else  /* __PRAGMA_REDEFINE_EXTNAME */
334 
335 extern char *__posix_asctime_r();
336 extern char *__posix_ctime_r();
337 
338 #ifdef	__lint
339 
340 #define	asctime_r __posix_asctime_r
341 #define	ctime_r __posix_ctime_r
342 
343 #else	/* !__lint */
344 
345 static char *
346 asctime_r(__tm, __buf)
347 	struct tm *__tm;
348 	char *__buf;
349 {
350 	return (__posix_asctime_r(__tm, __buf));
351 }
352 static char *
353 ctime_r(__time, __buf)
354 	time_t *__time;
355 	char *__buf;
356 {
357 	return (__posix_ctime_r(__time, __buf));
358 }
359 
360 #endif /* !__lint */
361 #endif /* __PRAGMA_REDEFINE_EXTNAME */
362 
363 #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
364 
365 extern char *asctime_r();
366 extern char *ctime_r();
367 
368 #endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
369 
370 #endif /* __STDC__ */
371 
372 #endif /* defined(__EXTENSIONS__) || defined(_REENTRANT)... */
373 
374 #ifdef	__cplusplus
375 }
376 #endif
377 
378 #endif	/* _TIME_H */
379