import tzdata 2017b
[unleashed.git] / include / time.h
blob4f4446e3fb3e8dca82f5186271dc124bef741327
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
21 /* Copyright (c) 1988 AT&T */
22 /* All Rights Reserved */
26 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
28 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
29 * Use is subject to license terms.
32 * Copyright 2010 Nexenta Systems, Inc. Al rights reserved.
33 * Copyright 2016 Joyent, Inc.
36 #ifndef _TIME_H
37 #define _TIME_H
39 #include <sys/feature_tests.h>
40 #include <iso/time_iso.h>
42 * C11 requires sys/time_impl.h for the definition of the struct timespec.
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)) ... */
51 * Allow global visibility for symbols defined in
52 * C++ "std" namespace in <iso/time_iso.h>.
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
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
74 #ifndef _CLOCKID_T
75 #define _CLOCKID_T
76 typedef int clockid_t;
77 #endif
79 #ifndef _TIMER_T
80 #define _TIMER_T
81 typedef int timer_t;
82 #endif
84 extern struct tm *gmtime_r(const time_t *_RESTRICT_KYWD,
85 struct tm *_RESTRICT_KYWD);
86 extern struct tm *localtime_r(const time_t *_RESTRICT_KYWD,
87 struct tm *_RESTRICT_KYWD);
89 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
90 defined(_XPG4) || defined(__EXTENSIONS__)
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 */
101 extern char *strptime(const char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
102 struct tm *_RESTRICT_KYWD);
104 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))... */
106 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
107 (_POSIX_C_SOURCE > 2) || defined(__EXTENSIONS__)
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>.
119 #ifndef _SIGVAL
120 #define _SIGVAL
121 union sigval {
122 int sival_int; /* integer value */
123 void *sival_ptr; /* pointer value */
125 #endif /* _SIGVAL */
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;
137 #endif /* _SIGEVENT */
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);
150 extern int nanosleep(const struct timespec *, struct timespec *);
151 extern int clock_nanosleep(clockid_t, int,
152 const struct timespec *, struct timespec *);
154 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))... */
156 #if !defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX) || \
157 defined(__EXTENSIONS__)
159 extern void tzset(void);
160 extern char *tzname[2];
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__) */
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
177 #endif /* !defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX)... */
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
187 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
188 defined(_XPG4_2) || defined(__EXTENSIONS__)
189 extern struct tm *getdate(const char *);
190 #undef getdate_err
191 #define getdate_err *(int *)_getdate_err_addr()
192 extern int *_getdate_err_addr(void);
193 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))... */
196 * ctime_r() & asctime_r() prototypes are defined here.
200 * Previous releases of Solaris, starting at 2.3, provided definitions of
201 * various functions as specified in POSIX.1c, Draft 6. For some of these
202 * functions, the final POSIX 1003.1c standard had a different number of
203 * arguments and return values.
205 * The following segment of this header provides support for the standard
206 * interfaces while supporting applications written under earlier
207 * releases. The application defines appropriate values of the feature
208 * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate
209 * whether it was written to expect the Draft 6 or standard versions of
210 * these interfaces, before including this header. This header then
211 * provides a mapping from the source version of the interface to an
212 * appropriate binary interface. Such mappings permit an application
213 * to be built from libraries and objects which have mixed expectations
214 * of the definitions of these functions.
216 * For applications using the Draft 6 definitions, the binary symbol is the
217 * same as the source symbol, and no explicit mapping is needed. For the
218 * standard interface, the function func() is mapped to the binary symbol
219 * _posix_func(). The preferred mechanism for the remapping is a compiler
220 * #pragma. If the compiler does not provide such a #pragma, the header file
221 * defines a static function func() which calls the _posix_func() version;
222 * this has to be done instead of #define since POSIX specifies that an
223 * application can #undef the symbol and still be bound to the correct
224 * implementation. Unfortunately, the statics confuse lint so we fallback to
225 * #define in that case.
227 * NOTE: Support for the Draft 6 definitions is provided for compatibility
228 * only. New applications/libraries should use the standard definitions.
231 #if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
233 #ifdef __PRAGMA_REDEFINE_EXTNAME
234 #pragma redefine_extname ctime_r __posix_ctime_r
235 #pragma redefine_extname asctime_r __posix_asctime_r
236 extern char *asctime_r(const struct tm *_RESTRICT_KYWD, char *_RESTRICT_KYWD);
237 extern char *ctime_r(const time_t *, char *);
238 #else /* __PRAGMA_REDEFINE_EXTNAME */
240 extern char *__posix_asctime_r(const struct tm *_RESTRICT_KYWD,
241 char *_RESTRICT_KYWD);
242 extern char *__posix_ctime_r(const time_t *, char *);
244 static char *
245 asctime_r(const struct tm *_RESTRICT_KYWD __tm, char *_RESTRICT_KYWD __buf)
247 return (__posix_asctime_r(__tm, __buf));
250 static char *
251 ctime_r(const time_t *__time, char *__buf)
253 return (__posix_ctime_r(__time, __buf));
256 #endif /* __PRAGMA_REDEFINE_EXTNAME */
258 #else /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
260 extern char *asctime_r(const struct tm *, char *, int);
261 extern char *ctime_r(const time_t *, char *, int);
263 #endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
266 #if defined(_XPG7) || !defined(_STRICT_SYMBOLS)
268 #ifndef _LOCALE_T
269 #define _LOCALE_T
270 typedef struct _locale *locale_t;
271 #endif
273 extern size_t strftime_l(char *_RESTRICT_KYWD, size_t,
274 const char *_RESTRICT_KYWD, const struct tm *_RESTRICT_KYWD, locale_t);
276 #endif /* defined(_XPG7) || !defined(_STRICT_SYMBOLS) */
278 #if !defined(_STRICT_SYMBOLS) || defined(_STDC_C11)
281 * Note, the C11 standard requires that all the various base values that are
282 * passed into timespec_get() be non-zero. Hence why TIME_UTC starts at one.
284 #define TIME_UTC 0x1 /* timespec_get base */
286 extern int timespec_get(struct timespec *, int);
287 #endif
289 #ifdef __cplusplus
291 #endif
293 #endif /* _TIME_H */