time.h revision 1.56 1 1.56 nia /* $NetBSD: time.h,v 1.56 2025/04/21 13:21:33 nia Exp $ */
2 1.9 cgd
3 1.7 cgd /*
4 1.15 perry * Copyright (c) 1989, 1993
5 1.15 perry * The Regents of the University of California. All rights reserved.
6 1.7 cgd * (c) UNIX System Laboratories, Inc.
7 1.7 cgd * All or some portions of this file are derived from material licensed
8 1.7 cgd * to the University of California by American Telephone and Telegraph
9 1.7 cgd * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 1.7 cgd * the permission of UNIX System Laboratories, Inc.
11 1.7 cgd *
12 1.7 cgd * Redistribution and use in source and binary forms, with or without
13 1.7 cgd * modification, are permitted provided that the following conditions
14 1.7 cgd * are met:
15 1.7 cgd * 1. Redistributions of source code must retain the above copyright
16 1.7 cgd * notice, this list of conditions and the following disclaimer.
17 1.7 cgd * 2. Redistributions in binary form must reproduce the above copyright
18 1.7 cgd * notice, this list of conditions and the following disclaimer in the
19 1.7 cgd * documentation and/or other materials provided with the distribution.
20 1.31 agc * 3. Neither the name of the University nor the names of its contributors
21 1.7 cgd * may be used to endorse or promote products derived from this software
22 1.7 cgd * without specific prior written permission.
23 1.7 cgd *
24 1.7 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.7 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.7 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.7 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.7 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.7 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.7 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.7 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.7 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.7 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.7 cgd * SUCH DAMAGE.
35 1.7 cgd *
36 1.15 perry * @(#)time.h 8.3 (Berkeley) 1/21/94
37 1.7 cgd */
38 1.7 cgd
39 1.7 cgd #ifndef _TIME_H_
40 1.7 cgd #define _TIME_H_
41 1.7 cgd
42 1.19 mycroft #include <sys/cdefs.h>
43 1.21 kleink #include <sys/featuretest.h>
44 1.7 cgd #include <machine/ansi.h>
45 1.7 cgd
46 1.24 kleink #include <sys/null.h>
47 1.7 cgd
48 1.8 cgd #ifdef _BSD_CLOCK_T_
49 1.8 cgd typedef _BSD_CLOCK_T_ clock_t;
50 1.8 cgd #undef _BSD_CLOCK_T_
51 1.7 cgd #endif
52 1.7 cgd
53 1.8 cgd #ifdef _BSD_TIME_T_
54 1.8 cgd typedef _BSD_TIME_T_ time_t;
55 1.8 cgd #undef _BSD_TIME_T_
56 1.7 cgd #endif
57 1.7 cgd
58 1.8 cgd #ifdef _BSD_SIZE_T_
59 1.8 cgd typedef _BSD_SIZE_T_ size_t;
60 1.8 cgd #undef _BSD_SIZE_T_
61 1.12 christos #endif
62 1.12 christos
63 1.12 christos #ifdef _BSD_CLOCKID_T_
64 1.12 christos typedef _BSD_CLOCKID_T_ clockid_t;
65 1.12 christos #undef _BSD_CLOCKID_T_
66 1.12 christos #endif
67 1.12 christos
68 1.12 christos #ifdef _BSD_TIMER_T_
69 1.12 christos typedef _BSD_TIMER_T_ timer_t;
70 1.12 christos #undef _BSD_TIMER_T_
71 1.7 cgd #endif
72 1.7 cgd
73 1.7 cgd #define CLOCKS_PER_SEC 100
74 1.7 cgd
75 1.7 cgd struct tm {
76 1.48 jschauma int tm_sec; /* seconds after the minute [0-60] */
77 1.7 cgd int tm_min; /* minutes after the hour [0-59] */
78 1.7 cgd int tm_hour; /* hours since midnight [0-23] */
79 1.7 cgd int tm_mday; /* day of the month [1-31] */
80 1.7 cgd int tm_mon; /* months since January [0-11] */
81 1.7 cgd int tm_year; /* years since 1900 */
82 1.7 cgd int tm_wday; /* days since Sunday [0-6] */
83 1.7 cgd int tm_yday; /* days since January 1 [0-365] */
84 1.49 rillig int tm_isdst; /* Daylight Saving Time flag */
85 1.25 hubertf long tm_gmtoff; /* offset from UTC in seconds */
86 1.18 mycroft __aconst char *tm_zone; /* timezone abbreviation */
87 1.7 cgd };
88 1.7 cgd
89 1.7 cgd __BEGIN_DECLS
90 1.34 perry char *asctime(const struct tm *);
91 1.34 perry clock_t clock(void);
92 1.38 christos #ifndef __LIBC12_SOURCE__
93 1.38 christos char *ctime(const time_t *) __RENAME(__ctime50);
94 1.38 christos double difftime(time_t, time_t) __RENAME(__difftime50);
95 1.38 christos struct tm *gmtime(const time_t *) __RENAME(__gmtime50);
96 1.38 christos struct tm *localtime(const time_t *) __RENAME(__locatime50);
97 1.38 christos time_t time(time_t *) __RENAME(__time50);
98 1.38 christos time_t mktime(struct tm *) __RENAME(__mktime50);
99 1.38 christos #endif
100 1.34 perry size_t strftime(char * __restrict, size_t, const char * __restrict,
101 1.37 christos const struct tm * __restrict)
102 1.37 christos __attribute__((__format__(__strftime__, 3, 0)));
103 1.7 cgd
104 1.30 bjh21 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
105 1.30 bjh21 defined(_NETBSD_SOURCE)
106 1.35 christos #ifndef __LIBC12_SOURCE__
107 1.28 perry /*
108 1.28 perry * CLK_TCK uses libc's internal __sysconf() to retrieve the machine's
109 1.29 bjh21 * HZ. The value of _SC_CLK_TCK is 39 -- we hard code it so we do not
110 1.28 perry * need to include unistd.h
111 1.28 perry */
112 1.34 perry long __sysconf(int);
113 1.29 bjh21 #define CLK_TCK (__sysconf(39))
114 1.35 christos #endif
115 1.29 bjh21 #endif
116 1.28 perry
117 1.18 mycroft extern __aconst char *tzname[2];
118 1.38 christos #ifndef __LIBC12_SOURCE__
119 1.38 christos void tzset(void) __RENAME(__tzset50);
120 1.38 christos #endif
121 1.7 cgd
122 1.21 kleink /*
123 1.21 kleink * X/Open Portability Guide >= Issue 4
124 1.21 kleink */
125 1.36 drochner #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
126 1.27 kleink extern int daylight;
127 1.27 kleink #ifndef __LIBC12_SOURCE__
128 1.27 kleink extern long int timezone __RENAME(__timezone13);
129 1.27 kleink #endif
130 1.34 perry char *strptime(const char * __restrict, const char * __restrict,
131 1.34 perry struct tm * __restrict);
132 1.21 kleink #endif
133 1.11 christos
134 1.39 ginsbach #if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
135 1.39 ginsbach defined(_NETBSD_SOURCE)
136 1.39 ginsbach struct tm *getdate(const char *);
137 1.39 ginsbach extern int getdate_err;
138 1.39 ginsbach #endif
139 1.39 ginsbach
140 1.50 rillig /* ISO/IEC 9899:2011 7.27.1/3 Components of time */
141 1.47 kamil #include <sys/timespec.h>
142 1.47 kamil
143 1.30 bjh21 #if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \
144 1.30 bjh21 defined(_NETBSD_SOURCE)
145 1.47 kamil #include <sys/time.h>
146 1.11 christos struct sigevent;
147 1.11 christos struct itimerspec;
148 1.41 christos int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
149 1.38 christos #ifndef __LIBC12_SOURCE__
150 1.38 christos int clock_getres(clockid_t, struct timespec *)
151 1.38 christos __RENAME(__clock_getres50);
152 1.38 christos int clock_gettime(clockid_t, struct timespec *)
153 1.38 christos __RENAME(__clock_gettime50);
154 1.38 christos int clock_settime(clockid_t, const struct timespec *)
155 1.38 christos __RENAME(__clock_settime50);
156 1.38 christos int nanosleep(const struct timespec *, struct timespec *)
157 1.38 christos __RENAME(__nanosleep50);
158 1.38 christos int timer_gettime(timer_t, struct itimerspec *) __RENAME(__timer_gettime50);
159 1.38 christos int timer_settime(timer_t, int, const struct itimerspec * __restrict,
160 1.38 christos struct itimerspec * __restrict) __RENAME(__timer_settime50);
161 1.38 christos #endif
162 1.46 christos #ifdef _NETBSD_SOURCE
163 1.46 christos #include <sys/idtype.h>
164 1.46 christos int clock_getcpuclockid2(idtype_t, id_t, clockid_t *);
165 1.46 christos #endif
166 1.46 christos int clock_getcpuclockid(pid_t, clockid_t *);
167 1.46 christos
168 1.34 perry int timer_create(clockid_t, struct sigevent * __restrict,
169 1.34 perry timer_t * __restrict);
170 1.34 perry int timer_delete(timer_t);
171 1.34 perry int timer_getoverrun(timer_t);
172 1.30 bjh21 #endif /* _POSIX_C_SOURCE >= 199309 || _XOPEN_SOURCE >= 500 || ... */
173 1.21 kleink
174 1.51 christos #if ((_POSIX_C_SOURCE - 0) >= 199506L && (_POSIX_C_SOURCE - 0) < 202405L) || \
175 1.51 christos (_XOPEN_SOURCE - 0) >= 500 || defined(_REENTRANT) || defined(_NETBSD_SOURCE)
176 1.34 perry char *asctime_r(const struct tm * __restrict, char * __restrict);
177 1.38 christos #ifndef __LIBC12_SOURCE__
178 1.38 christos char *ctime_r(const time_t *, char *) __RENAME(__ctime_r50);
179 1.51 christos #endif
180 1.51 christos #endif
181 1.52 christos
182 1.51 christos #if (_POSIX_C_SOURCE - 0) >= 199506L || \
183 1.51 christos (_XOPEN_SOURCE - 0) >= 500 || defined(_REENTRANT) || defined(_NETBSD_SOURCE)
184 1.52 christos #ifndef __LIBC12_SOURCE__
185 1.52 christos struct tm *gmtime_r(const time_t * __restrict, struct tm * __restrict)
186 1.52 christos __RENAME(__gmtime_r50);
187 1.38 christos struct tm *localtime_r(const time_t * __restrict, struct tm * __restrict)
188 1.38 christos __RENAME(__localtime_r50);
189 1.38 christos #endif
190 1.53 kre #endif
191 1.21 kleink
192 1.43 joerg #if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
193 1.43 joerg # ifndef __LOCALE_T_DECLARED
194 1.43 joerg typedef struct _locale *locale_t;
195 1.43 joerg # define __LOCALE_T_DECLARED
196 1.43 joerg # endif
197 1.43 joerg size_t strftime_l(char * __restrict, size_t, const char * __restrict,
198 1.43 joerg const struct tm * __restrict, locale_t)
199 1.43 joerg __attribute__((__format__(__strftime__, 3, 0)));
200 1.43 joerg #endif
201 1.43 joerg
202 1.54 nia #if (__STDC_VERSION__ - 0 >= 202311L) || defined(_ISOC23_SOURCE) || \
203 1.54 nia defined(_NETBSD_SOURCE)
204 1.54 nia #ifndef __LIBC12_SOURCE__
205 1.54 nia time_t timegm(struct tm *) __RENAME(__timegm50);
206 1.54 nia #endif
207 1.54 nia #endif
208 1.54 nia
209 1.30 bjh21 #if defined(_NETBSD_SOURCE)
210 1.40 christos typedef struct __state *timezone_t;
211 1.40 christos
212 1.38 christos #ifndef __LIBC12_SOURCE__
213 1.38 christos time_t time2posix(time_t) __RENAME(__time2posix50);
214 1.38 christos time_t posix2time(time_t) __RENAME(__posix2time50);
215 1.38 christos time_t timeoff(struct tm *, long) __RENAME(__timeoff50);
216 1.38 christos time_t timelocal(struct tm *) __RENAME(__timelocal50);
217 1.38 christos struct tm *offtime(const time_t *, long) __RENAME(__offtime50);
218 1.38 christos void tzsetwall(void) __RENAME(__tzsetwall50);
219 1.40 christos
220 1.40 christos struct tm *offtime_r(const time_t *, long, struct tm *) __RENAME(__offtime_r50);
221 1.44 christos struct tm *localtime_rz(timezone_t __restrict, const time_t * __restrict,
222 1.40 christos struct tm * __restrict) __RENAME(__localtime_rz50);
223 1.44 christos char *ctime_rz(timezone_t __restrict, const time_t *, char *)
224 1.44 christos __RENAME(__ctime_rz50);
225 1.44 christos time_t mktime_z(timezone_t __restrict, struct tm * __restrict)
226 1.44 christos __RENAME(__mktime_z50);
227 1.44 christos time_t timelocal_z(timezone_t __restrict, struct tm *)
228 1.44 christos __RENAME(__timelocal_z50);
229 1.44 christos time_t time2posix_z(timezone_t __restrict, time_t) __RENAME(__time2posix_z50);
230 1.44 christos time_t posix2time_z(timezone_t __restrict, time_t) __RENAME(__posix2time_z50);
231 1.40 christos timezone_t tzalloc(const char *) __RENAME(__tzalloc50);
232 1.44 christos void tzfree(timezone_t __restrict) __RENAME(__tzfree50);
233 1.44 christos const char *tzgetname(timezone_t __restrict, int) __RENAME(__tzgetname50);
234 1.45 christos long tzgetgmtoff(timezone_t __restrict, int) __RENAME(__tzgetgmtoff50);
235 1.40 christos #endif
236 1.40 christos
237 1.44 christos size_t strftime_lz(timezone_t __restrict, char * __restrict, size_t,
238 1.43 joerg const char * __restrict, const struct tm * __restrict, locale_t)
239 1.43 joerg __attribute__((__format__(__strftime__, 4, 0)));
240 1.44 christos size_t strftime_z(timezone_t __restrict, char * __restrict, size_t,
241 1.40 christos const char * __restrict, const struct tm * __restrict)
242 1.40 christos __attribute__((__format__(__strftime__, 4, 0)));
243 1.42 joerg char *strptime_l(const char * __restrict, const char * __restrict,
244 1.42 joerg struct tm * __restrict, locale_t);
245 1.42 joerg
246 1.30 bjh21 #endif /* _NETBSD_SOURCE */
247 1.21 kleink
248 1.50 rillig /* ISO/IEC 9899:2011 7.27.2.5 The timespec_get function */
249 1.56 nia #if defined(_ISOC11_SOURCE) || (__STDC_VERSION__ - 0) >= 201101L || \
250 1.56 nia defined(_NETBSD_SOURCE) || (__cplusplus - 0) >= 201103L || \
251 1.56 nia (_POSIX_C_SOURCE - 0) >= 202405L
252 1.56 nia
253 1.47 kamil #define TIME_UTC 1 /* time elapsed since epoch */
254 1.55 nia #if (__STDC_VERSION__ - 0 >= 202311L) || defined(_ISOC23_SOURCE) || \
255 1.55 nia defined(_NETBSD_SOURCE)
256 1.55 nia #define TIME_MONOTONIC 2
257 1.55 nia #endif
258 1.56 nia
259 1.47 kamil int timespec_get(struct timespec *ts, int base);
260 1.56 nia #if (__STDC_VERSION__ - 0 >= 202311L) || defined(_ISOC23_SOURCE) || \
261 1.56 nia defined(_NETBSD_SOURCE)
262 1.56 nia int timespec_getres(struct timespec *ts, int base);
263 1.56 nia #endif
264 1.56 nia #endif
265 1.47 kamil
266 1.7 cgd __END_DECLS
267 1.7 cgd
268 1.7 cgd #endif /* !_TIME_H_ */
269