7064 TCP_KEEPIDLE has needless 10sec minimum
[unleashed.git] / usr / src / head / time.h
blobbf27e0f0ce0979e88534fc0270ec4b0e1bc1872c
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 #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
93 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
94 defined(_XPG4) || defined(__EXTENSIONS__)
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 */
105 extern char *strptime(const char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
106 struct tm *_RESTRICT_KYWD);
108 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))... */
110 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
111 (_POSIX_C_SOURCE > 2) || defined(__EXTENSIONS__)
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>.
123 #ifndef _SIGVAL
124 #define _SIGVAL
125 union sigval {
126 int sival_int; /* integer value */
127 void *sival_ptr; /* pointer value */
129 #endif /* _SIGVAL */
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;
141 #endif /* _SIGEVENT */
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);
154 extern int nanosleep(const struct timespec *, struct timespec *);
155 extern int clock_nanosleep(clockid_t, int,
156 const struct timespec *, struct timespec *);
158 #endif /* (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))... */
160 #if !defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX) || \
161 defined(__EXTENSIONS__)
163 extern void tzset(void);
164 extern char *tzname[2];
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__) */
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
181 #endif /* !defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX)... */
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
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))... */
204 * ctime_r() & asctime_r() prototypes are defined here.
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.
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.
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.
235 * NOTE: Support for the Draft 6 definitions is provided for compatibility
236 * only. New applications/libraries should use the standard definitions.
239 #if defined(__EXTENSIONS__) || defined(_REENTRANT) || \
240 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
241 (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
243 #if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
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 */
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 *);
256 #ifdef __lint
258 #define ctime_r __posix_ctime_r
259 #define asctime_r __posix_asctime_r
261 #else /* !__lint */
263 static char *
264 asctime_r(const struct tm *_RESTRICT_KYWD __tm, char *_RESTRICT_KYWD __buf)
266 return (__posix_asctime_r(__tm, __buf));
269 static char *
270 ctime_r(const time_t *__time, char *__buf)
272 return (__posix_ctime_r(__time, __buf));
275 #endif /* !__lint */
276 #endif /* __PRAGMA_REDEFINE_EXTNAME */
278 #else /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
280 extern char *asctime_r(const struct tm *, char *, int);
281 extern char *ctime_r(const time_t *, char *, int);
283 #endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
285 #endif /* defined(__EXTENSIONS__) || defined(_REENTRANT)... */
288 #if defined(_XPG7) || !defined(_STRICT_SYMBOLS)
290 #ifndef _LOCALE_T
291 #define _LOCALE_T
292 typedef struct _locale *locale_t;
293 #endif
295 extern size_t strftime_l(char *_RESTRICT_KYWD, size_t,
296 const char *_RESTRICT_KYWD, const struct tm *_RESTRICT_KYWD, locale_t);
298 #endif /* defined(_XPG7) || !defined(_STRICT_SYMBOLS) */
300 #if !defined(_STRICT_SYMBOLS) || defined(_STDC_C11)
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.
306 #define TIME_UTC 0x1 /* timespec_get base */
308 extern int timespec_get(struct timespec *, int);
309 #endif
311 #ifdef __cplusplus
313 #endif
315 #endif /* _TIME_H */