xref: /freebsd/include/time.h (revision 224ee591e78db1dad63dc81d565b4629308c41f9)
159deaec5SRodney W. Grimes /*
259deaec5SRodney W. Grimes  * Copyright (c) 1989, 1993
359deaec5SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
459deaec5SRodney W. Grimes  * (c) UNIX System Laboratories, Inc.
559deaec5SRodney W. Grimes  * All or some portions of this file are derived from material licensed
659deaec5SRodney W. Grimes  * to the University of California by American Telephone and Telegraph
759deaec5SRodney W. Grimes  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
859deaec5SRodney W. Grimes  * the permission of UNIX System Laboratories, Inc.
959deaec5SRodney W. Grimes  *
1059deaec5SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
1159deaec5SRodney W. Grimes  * modification, are permitted provided that the following conditions
1259deaec5SRodney W. Grimes  * are met:
1359deaec5SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
1459deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
1559deaec5SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
1659deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
1759deaec5SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18f2556687SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
1959deaec5SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
2059deaec5SRodney W. Grimes  *    without specific prior written permission.
2159deaec5SRodney W. Grimes  *
2259deaec5SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2359deaec5SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2459deaec5SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2559deaec5SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2659deaec5SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2759deaec5SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2859deaec5SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2959deaec5SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3059deaec5SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3159deaec5SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3259deaec5SRodney W. Grimes  * SUCH DAMAGE.
3359deaec5SRodney W. Grimes  *
3459deaec5SRodney W. Grimes  *	@(#)time.h	8.3 (Berkeley) 1/21/94
3559deaec5SRodney W. Grimes  */
3659deaec5SRodney W. Grimes 
375b32a38aSPoul-Henning Kamp /*
385b32a38aSPoul-Henning Kamp  * $FreeBSD$
395b32a38aSPoul-Henning Kamp  */
405b32a38aSPoul-Henning Kamp 
4159deaec5SRodney W. Grimes #ifndef _TIME_H_
4259deaec5SRodney W. Grimes #define	_TIME_H_
4359deaec5SRodney W. Grimes 
441cb2a9aeSGarrett Wollman #include <sys/cdefs.h>
4512eb46c8SMarcel Moolenaar #include <sys/_null.h>
46abbd8902SMike Barcroft #include <sys/_types.h>
47abbd8902SMike Barcroft 
4873cf72f5SGarrett Wollman #if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE
49339b0f68SBruce Evans /*
50339b0f68SBruce Evans  * Frequency of the clock ticks reported by times().  Deprecated - use
511cb2a9aeSGarrett Wollman  * sysconf(_SC_CLK_TCK) instead.  (Removed in 1003.1-2001.)
52339b0f68SBruce Evans  */
53dd1b6791SMike Barcroft #define	CLK_TCK		128
54339b0f68SBruce Evans #endif
55339b0f68SBruce Evans 
56339b0f68SBruce Evans /* Frequency of the clock ticks reported by clock().  */
57dd1b6791SMike Barcroft #define	CLOCKS_PER_SEC	128
58339b0f68SBruce Evans 
59abbd8902SMike Barcroft #ifndef _CLOCK_T_DECLARED
60abbd8902SMike Barcroft typedef	__clock_t	clock_t;
61abbd8902SMike Barcroft #define	_CLOCK_T_DECLARED
6259deaec5SRodney W. Grimes #endif
6359deaec5SRodney W. Grimes 
64abbd8902SMike Barcroft #ifndef _TIME_T_DECLARED
65abbd8902SMike Barcroft typedef	__time_t	time_t;
66abbd8902SMike Barcroft #define	_TIME_T_DECLARED
6759deaec5SRodney W. Grimes #endif
6859deaec5SRodney W. Grimes 
69abbd8902SMike Barcroft #ifndef _SIZE_T_DECLARED
70abbd8902SMike Barcroft typedef	__size_t	size_t;
71abbd8902SMike Barcroft #define	_SIZE_T_DECLARED
72f154fbdaSPeter Wemm #endif
73f154fbdaSPeter Wemm 
741cb2a9aeSGarrett Wollman #if __POSIX_VISIBLE >= 199309
75f154fbdaSPeter Wemm /*
76f154fbdaSPeter Wemm  * New in POSIX 1003.1b-1993.
77f154fbdaSPeter Wemm  */
78abbd8902SMike Barcroft #ifndef _CLOCKID_T_DECLARED
79abbd8902SMike Barcroft typedef	__clockid_t	clockid_t;
80abbd8902SMike Barcroft #define	_CLOCKID_T_DECLARED
819e0eb33eSAndrey A. Chernov #endif
829e0eb33eSAndrey A. Chernov 
83abbd8902SMike Barcroft #ifndef _TIMER_T_DECLARED
84abbd8902SMike Barcroft typedef	__timer_t	timer_t;
85abbd8902SMike Barcroft #define	_TIMER_T_DECLARED
8659deaec5SRodney W. Grimes #endif
8759deaec5SRodney W. Grimes 
881cb2a9aeSGarrett Wollman #include <sys/timespec.h>
891cb2a9aeSGarrett Wollman #endif /* __POSIX_VISIBLE >= 199309 */
90f154fbdaSPeter Wemm 
91*224ee591SDavid Xu #if __POSIX_VISIBLE >= 200112
92*224ee591SDavid Xu #ifndef _PID_T_DECLARED
93*224ee591SDavid Xu typedef	__pid_t		pid_t;
94*224ee591SDavid Xu #define	_PID_T_DECLARED
95*224ee591SDavid Xu #endif
96*224ee591SDavid Xu #endif
97*224ee591SDavid Xu 
986d2f64c1SDavid Schultz /* These macros are also in sys/time.h. */
996d2f64c1SDavid Schultz #if !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 200112
1006d2f64c1SDavid Schultz #define CLOCK_REALTIME	0
1016d2f64c1SDavid Schultz #ifdef __BSD_VISIBLE
1026d2f64c1SDavid Schultz #define CLOCK_VIRTUAL	1
1036d2f64c1SDavid Schultz #define CLOCK_PROF	2
1046d2f64c1SDavid Schultz #endif
1056d2f64c1SDavid Schultz #define CLOCK_MONOTONIC	4
106992879a0SJohn Birrell #define CLOCK_UPTIME	5		/* FreeBSD-specific. */
107992879a0SJohn Birrell #define CLOCK_UPTIME_PRECISE	7	/* FreeBSD-specific. */
108992879a0SJohn Birrell #define CLOCK_UPTIME_FAST	8	/* FreeBSD-specific. */
109992879a0SJohn Birrell #define CLOCK_REALTIME_PRECISE	9	/* FreeBSD-specific. */
110992879a0SJohn Birrell #define CLOCK_REALTIME_FAST	10	/* FreeBSD-specific. */
111992879a0SJohn Birrell #define CLOCK_MONOTONIC_PRECISE	11	/* FreeBSD-specific. */
112992879a0SJohn Birrell #define CLOCK_MONOTONIC_FAST	12	/* FreeBSD-specific. */
113992879a0SJohn Birrell #define CLOCK_SECOND	13		/* FreeBSD-specific. */
1149939a136SDavid Xu #define CLOCK_THREAD_CPUTIME_ID	14
1156d2f64c1SDavid Schultz #endif /* !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 200112 */
1166d2f64c1SDavid Schultz 
1176d2f64c1SDavid Schultz #if !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 200112
1186d2f64c1SDavid Schultz #if __BSD_VISIBLE
1196d2f64c1SDavid Schultz #define TIMER_RELTIME	0x0	/* relative timer */
1206d2f64c1SDavid Schultz #endif
1216d2f64c1SDavid Schultz #define TIMER_ABSTIME	0x1	/* absolute timer */
1226d2f64c1SDavid Schultz #endif /* !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 200112 */
1236d2f64c1SDavid Schultz 
12459deaec5SRodney W. Grimes struct tm {
12559deaec5SRodney W. Grimes 	int	tm_sec;		/* seconds after the minute [0-60] */
12659deaec5SRodney W. Grimes 	int	tm_min;		/* minutes after the hour [0-59] */
12759deaec5SRodney W. Grimes 	int	tm_hour;	/* hours since midnight [0-23] */
12859deaec5SRodney W. Grimes 	int	tm_mday;	/* day of the month [1-31] */
12959deaec5SRodney W. Grimes 	int	tm_mon;		/* months since January [0-11] */
13059deaec5SRodney W. Grimes 	int	tm_year;	/* years since 1900 */
13159deaec5SRodney W. Grimes 	int	tm_wday;	/* days since Sunday [0-6] */
13259deaec5SRodney W. Grimes 	int	tm_yday;	/* days since January 1 [0-365] */
13359deaec5SRodney W. Grimes 	int	tm_isdst;	/* Daylight Savings Time flag */
1345b32a38aSPoul-Henning Kamp 	long	tm_gmtoff;	/* offset from UTC in seconds */
13559deaec5SRodney W. Grimes 	char	*tm_zone;	/* timezone abbreviation */
13659deaec5SRodney W. Grimes };
13759deaec5SRodney W. Grimes 
1381cb2a9aeSGarrett Wollman #if __POSIX_VISIBLE
1392bd32397SJoseph Koshy extern char *tzname[];
1402bd32397SJoseph Koshy #endif
1412bd32397SJoseph Koshy 
14259deaec5SRodney W. Grimes __BEGIN_DECLS
143bb28f3c2SWarner Losh char *asctime(const struct tm *);
144bb28f3c2SWarner Losh clock_t clock(void);
145bb28f3c2SWarner Losh char *ctime(const time_t *);
146bb28f3c2SWarner Losh double difftime(time_t, time_t);
1476d2f64c1SDavid Schultz /* XXX missing: getdate() */
148bb28f3c2SWarner Losh struct tm *gmtime(const time_t *);
149bb28f3c2SWarner Losh struct tm *localtime(const time_t *);
150bb28f3c2SWarner Losh time_t mktime(struct tm *);
151620035efSRobert Drehmel size_t strftime(char * __restrict, size_t, const char * __restrict,
152620035efSRobert Drehmel     const struct tm * __restrict);
153bb28f3c2SWarner Losh time_t time(time_t *);
154bd3e40ceSDavid Xu #if __POSIX_VISIBLE >= 200112
155bd3e40ceSDavid Xu struct sigevent;
156bd3e40ceSDavid Xu int timer_create(clockid_t, struct sigevent *__restrict, timer_t *__restrict);
157bd3e40ceSDavid Xu int timer_delete(timer_t);
158bd3e40ceSDavid Xu int timer_gettime(timer_t, struct itimerspec *);
159bd3e40ceSDavid Xu int timer_getoverrun(timer_t);
160bd3e40ceSDavid Xu int timer_settime(timer_t, int, const struct itimerspec *__restrict,
161bd3e40ceSDavid Xu 	struct itimerspec *__restrict);
162bd3e40ceSDavid Xu #endif
1631cb2a9aeSGarrett Wollman #if __POSIX_VISIBLE
164bb28f3c2SWarner Losh void tzset(void);
1651cb2a9aeSGarrett Wollman #endif
1661cb2a9aeSGarrett Wollman 
167b8c54054SGarrett Wollman #if __POSIX_VISIBLE >= 199309
168b8c54054SGarrett Wollman int clock_getres(clockid_t, struct timespec *);
169b8c54054SGarrett Wollman int clock_gettime(clockid_t, struct timespec *);
170b8c54054SGarrett Wollman int clock_settime(clockid_t, const struct timespec *);
1716d2f64c1SDavid Schultz /* XXX missing: clock_nanosleep() */
172b8c54054SGarrett Wollman int nanosleep(const struct timespec *, struct timespec *);
173b8c54054SGarrett Wollman #endif /* __POSIX_VISIBLE >= 199309 */
174b8c54054SGarrett Wollman 
175*224ee591SDavid Xu #if __POSIX_VISIBLE >= 200112
176*224ee591SDavid Xu int clock_getcpuclockid(pid_t, clockid_t *);
177*224ee591SDavid Xu #endif
178*224ee591SDavid Xu 
179b3ab54e1SGarrett Wollman #if __POSIX_VISIBLE >= 199506
180b3ab54e1SGarrett Wollman char *asctime_r(const struct tm *, char *);
181b3ab54e1SGarrett Wollman char *ctime_r(const time_t *, char *);
182b3ab54e1SGarrett Wollman struct tm *gmtime_r(const time_t *, struct tm *);
183b3ab54e1SGarrett Wollman struct tm *localtime_r(const time_t *, struct tm *);
184b3ab54e1SGarrett Wollman #endif
185b3ab54e1SGarrett Wollman 
1861cb2a9aeSGarrett Wollman #if __XSI_VISIBLE
187d542f511SRobert Drehmel char *strptime(const char * __restrict, const char * __restrict,
188d542f511SRobert Drehmel     struct tm * __restrict);
1891cb2a9aeSGarrett Wollman #endif
1901cb2a9aeSGarrett Wollman 
1911cb2a9aeSGarrett Wollman #if __BSD_VISIBLE
1926d2f64c1SDavid Schultz char *timezone(int, int);	/* XXX XSI conflict */
193bb28f3c2SWarner Losh void tzsetwall(void);
194bb28f3c2SWarner Losh time_t timelocal(struct tm * const);
195bb28f3c2SWarner Losh time_t timegm(struct tm * const);
1961cb2a9aeSGarrett Wollman #endif /* __BSD_VISIBLE */
197a8ed63bbSDavid Chisnall 
1983ac9d659SDavid Chisnall #if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_)
199a8ed63bbSDavid Chisnall #include <xlocale/_time.h>
200a8ed63bbSDavid Chisnall #endif
20159deaec5SRodney W. Grimes __END_DECLS
20259deaec5SRodney W. Grimes 
20359deaec5SRodney W. Grimes #endif /* !_TIME_H_ */
204