xref: /freebsd/include/time.h (revision 190cef3d)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  * (c) UNIX System Laboratories, Inc.
7  * All or some portions of this file are derived from material licensed
8  * to the University of California by American Telephone and Telegraph
9  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10  * the permission of UNIX System Laboratories, Inc.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *	@(#)time.h	8.3 (Berkeley) 1/21/94
37  */
38 
39 /*
40  * $FreeBSD$
41  */
42 
43 #ifndef _TIME_H_
44 #define	_TIME_H_
45 
46 #include <sys/cdefs.h>
47 #include <sys/_null.h>
48 #include <sys/_types.h>
49 
50 #if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE
51 /*
52  * Frequency of the clock ticks reported by times().  Deprecated - use
53  * sysconf(_SC_CLK_TCK) instead.  (Removed in 1003.1-2001.)
54  */
55 #define	CLK_TCK		128
56 #endif
57 
58 /* Frequency of the clock ticks reported by clock().  */
59 #define	CLOCKS_PER_SEC	128
60 
61 #ifndef _CLOCK_T_DECLARED
62 typedef	__clock_t	clock_t;
63 #define	_CLOCK_T_DECLARED
64 #endif
65 
66 #ifndef _TIME_T_DECLARED
67 typedef	__time_t	time_t;
68 #define	_TIME_T_DECLARED
69 #endif
70 
71 #ifndef _SIZE_T_DECLARED
72 typedef	__size_t	size_t;
73 #define	_SIZE_T_DECLARED
74 #endif
75 
76 #if __POSIX_VISIBLE >= 199309
77 /*
78  * New in POSIX 1003.1b-1993.
79  */
80 #ifndef _CLOCKID_T_DECLARED
81 typedef	__clockid_t	clockid_t;
82 #define	_CLOCKID_T_DECLARED
83 #endif
84 
85 #ifndef _TIMER_T_DECLARED
86 typedef	__timer_t	timer_t;
87 #define	_TIMER_T_DECLARED
88 #endif
89 
90 #include <sys/timespec.h>
91 #endif /* __POSIX_VISIBLE >= 199309 */
92 
93 #if __POSIX_VISIBLE >= 200112
94 #ifndef _PID_T_DECLARED
95 typedef	__pid_t		pid_t;
96 #define	_PID_T_DECLARED
97 #endif
98 #endif
99 
100 /* These macros are also in sys/time.h. */
101 #if !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 200112
102 #define CLOCK_REALTIME	0
103 #ifdef __BSD_VISIBLE
104 #define CLOCK_VIRTUAL	1
105 #define CLOCK_PROF	2
106 #endif
107 #define CLOCK_MONOTONIC	4
108 #define CLOCK_UPTIME	5		/* FreeBSD-specific. */
109 #define CLOCK_UPTIME_PRECISE	7	/* FreeBSD-specific. */
110 #define CLOCK_UPTIME_FAST	8	/* FreeBSD-specific. */
111 #define CLOCK_REALTIME_PRECISE	9	/* FreeBSD-specific. */
112 #define CLOCK_REALTIME_FAST	10	/* FreeBSD-specific. */
113 #define CLOCK_MONOTONIC_PRECISE	11	/* FreeBSD-specific. */
114 #define CLOCK_MONOTONIC_FAST	12	/* FreeBSD-specific. */
115 #define CLOCK_SECOND	13		/* FreeBSD-specific. */
116 #define CLOCK_THREAD_CPUTIME_ID	14
117 #define	CLOCK_PROCESS_CPUTIME_ID	15
118 #endif /* !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 200112 */
119 
120 #if !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 200112
121 #if __BSD_VISIBLE
122 #define TIMER_RELTIME	0x0	/* relative timer */
123 #endif
124 #define TIMER_ABSTIME	0x1	/* absolute timer */
125 #endif /* !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 200112 */
126 
127 struct tm {
128 	int	tm_sec;		/* seconds after the minute [0-60] */
129 	int	tm_min;		/* minutes after the hour [0-59] */
130 	int	tm_hour;	/* hours since midnight [0-23] */
131 	int	tm_mday;	/* day of the month [1-31] */
132 	int	tm_mon;		/* months since January [0-11] */
133 	int	tm_year;	/* years since 1900 */
134 	int	tm_wday;	/* days since Sunday [0-6] */
135 	int	tm_yday;	/* days since January 1 [0-365] */
136 	int	tm_isdst;	/* Daylight Savings Time flag */
137 	long	tm_gmtoff;	/* offset from UTC in seconds */
138 	char	*tm_zone;	/* timezone abbreviation */
139 };
140 
141 #if __POSIX_VISIBLE
142 extern char *tzname[];
143 #endif
144 
145 __BEGIN_DECLS
146 char *asctime(const struct tm *);
147 clock_t clock(void);
148 char *ctime(const time_t *);
149 #ifndef _STANDALONE
150 double difftime(time_t, time_t);
151 #endif
152 /* XXX missing: getdate() */
153 struct tm *gmtime(const time_t *);
154 struct tm *localtime(const time_t *);
155 time_t mktime(struct tm *);
156 size_t strftime(char * __restrict, size_t, const char * __restrict,
157     const struct tm * __restrict);
158 time_t time(time_t *);
159 #if __POSIX_VISIBLE >= 200112
160 struct sigevent;
161 int timer_create(clockid_t, struct sigevent *__restrict, timer_t *__restrict);
162 int timer_delete(timer_t);
163 int timer_gettime(timer_t, struct itimerspec *);
164 int timer_getoverrun(timer_t);
165 int timer_settime(timer_t, int, const struct itimerspec *__restrict,
166 	struct itimerspec *__restrict);
167 #endif
168 #if __POSIX_VISIBLE
169 void tzset(void);
170 #endif
171 
172 #if __POSIX_VISIBLE >= 199309
173 int clock_getres(clockid_t, struct timespec *);
174 int clock_gettime(clockid_t, struct timespec *);
175 int clock_settime(clockid_t, const struct timespec *);
176 int nanosleep(const struct timespec *, struct timespec *);
177 #endif /* __POSIX_VISIBLE >= 199309 */
178 
179 #if __POSIX_VISIBLE >= 200112
180 int clock_getcpuclockid(pid_t, clockid_t *);
181 int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *);
182 #endif
183 
184 #if __POSIX_VISIBLE >= 199506
185 char *asctime_r(const struct tm *, char *);
186 char *ctime_r(const time_t *, char *);
187 struct tm *gmtime_r(const time_t *, struct tm *);
188 struct tm *localtime_r(const time_t *, struct tm *);
189 #endif
190 
191 #if __XSI_VISIBLE
192 char *strptime(const char * __restrict, const char * __restrict,
193     struct tm * __restrict);
194 #endif
195 
196 #if __BSD_VISIBLE
197 char *timezone(int, int);	/* XXX XSI conflict */
198 void tzsetwall(void);
199 time_t timelocal(struct tm * const);
200 time_t timegm(struct tm * const);
201 int timer_oshandle_np(timer_t timerid);
202 time_t time2posix(time_t t);
203 time_t posix2time(time_t t);
204 #endif /* __BSD_VISIBLE */
205 
206 #if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_)
207 #include <xlocale/_time.h>
208 #endif
209 
210 /* ISO/IEC 9899:201x 7.27.2.5 The timespec_get function */
211 #define TIME_UTC	1	/* time elapsed since epoch */
212 int timespec_get(struct timespec *ts, int base);
213 
214 __END_DECLS
215 
216 #endif /* !_TIME_H_ */
217