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