time.h revision 233600
11539Srgrimes/*
21539Srgrimes * Copyright (c) 1989, 1993
31539Srgrimes *	The Regents of the University of California.  All rights reserved.
41539Srgrimes * (c) UNIX System Laboratories, Inc.
51539Srgrimes * All or some portions of this file are derived from material licensed
61539Srgrimes * to the University of California by American Telephone and Telegraph
71539Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
81539Srgrimes * the permission of UNIX System Laboratories, Inc.
91539Srgrimes *
101539Srgrimes * Redistribution and use in source and binary forms, with or without
111539Srgrimes * modification, are permitted provided that the following conditions
121539Srgrimes * are met:
131539Srgrimes * 1. Redistributions of source code must retain the above copyright
141539Srgrimes *    notice, this list of conditions and the following disclaimer.
151539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161539Srgrimes *    notice, this list of conditions and the following disclaimer in the
171539Srgrimes *    documentation and/or other materials provided with the distribution.
18203964Simp * 3. Neither the name of the University nor the names of its contributors
191539Srgrimes *    may be used to endorse or promote products derived from this software
201539Srgrimes *    without specific prior written permission.
211539Srgrimes *
221539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321539Srgrimes * SUCH DAMAGE.
331539Srgrimes *
341539Srgrimes *	@(#)time.h	8.3 (Berkeley) 1/21/94
351539Srgrimes */
361539Srgrimes
3775033Sphk/*
3875033Sphk * $FreeBSD: head/include/time.h 233600 2012-03-28 12:11:54Z theraven $
3975033Sphk */
4075033Sphk
411539Srgrimes#ifndef _TIME_H_
421539Srgrimes#define	_TIME_H_
431539Srgrimes
4498269Swollman#include <sys/cdefs.h>
45123257Smarcel#include <sys/_null.h>
46102227Smike#include <sys/_types.h>
47102227Smike
4898312Swollman#if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE
496164Sbde/*
506164Sbde * Frequency of the clock ticks reported by times().  Deprecated - use
5198269Swollman * sysconf(_SC_CLK_TCK) instead.  (Removed in 1003.1-2001.)
526164Sbde */
53102874Smike#define	CLK_TCK		128
546164Sbde#endif
556164Sbde
566164Sbde/* Frequency of the clock ticks reported by clock().  */
57102874Smike#define	CLOCKS_PER_SEC	128
586164Sbde
59102227Smike#ifndef _CLOCK_T_DECLARED
60102227Smiketypedef	__clock_t	clock_t;
61102227Smike#define	_CLOCK_T_DECLARED
621539Srgrimes#endif
631539Srgrimes
64102227Smike#ifndef _TIME_T_DECLARED
65102227Smiketypedef	__time_t	time_t;
66102227Smike#define	_TIME_T_DECLARED
671539Srgrimes#endif
681539Srgrimes
69102227Smike#ifndef _SIZE_T_DECLARED
70102227Smiketypedef	__size_t	size_t;
71102227Smike#define	_SIZE_T_DECLARED
7225773Speter#endif
7325773Speter
7498269Swollman#if __POSIX_VISIBLE >= 199309
7525773Speter/*
7625773Speter * New in POSIX 1003.1b-1993.
7725773Speter */
78102227Smike#ifndef _CLOCKID_T_DECLARED
79102227Smiketypedef	__clockid_t	clockid_t;
80102227Smike#define	_CLOCKID_T_DECLARED
8125769Sache#endif
8225769Sache
83102227Smike#ifndef _TIMER_T_DECLARED
84102227Smiketypedef	__timer_t	timer_t;
85102227Smike#define	_TIMER_T_DECLARED
861539Srgrimes#endif
871539Srgrimes
8898269Swollman#include <sys/timespec.h>
8998269Swollman#endif /* __POSIX_VISIBLE >= 199309 */
9025773Speter
91144529Sdas/* These macros are also in sys/time.h. */
92144529Sdas#if !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 200112
93144529Sdas#define CLOCK_REALTIME	0
94144529Sdas#ifdef __BSD_VISIBLE
95144529Sdas#define CLOCK_VIRTUAL	1
96144529Sdas#define CLOCK_PROF	2
97144529Sdas#endif
98144529Sdas#define CLOCK_MONOTONIC	4
99157766Sjb#define CLOCK_UPTIME	5		/* FreeBSD-specific. */
100157766Sjb#define CLOCK_UPTIME_PRECISE	7	/* FreeBSD-specific. */
101157766Sjb#define CLOCK_UPTIME_FAST	8	/* FreeBSD-specific. */
102157766Sjb#define CLOCK_REALTIME_PRECISE	9	/* FreeBSD-specific. */
103157766Sjb#define CLOCK_REALTIME_FAST	10	/* FreeBSD-specific. */
104157766Sjb#define CLOCK_MONOTONIC_PRECISE	11	/* FreeBSD-specific. */
105157766Sjb#define CLOCK_MONOTONIC_FAST	12	/* FreeBSD-specific. */
106157766Sjb#define CLOCK_SECOND	13		/* FreeBSD-specific. */
107177494Sdavidxu#define CLOCK_THREAD_CPUTIME_ID	14
108144529Sdas#endif /* !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 200112 */
109144529Sdas
110144529Sdas#if !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 200112
111144529Sdas#if __BSD_VISIBLE
112144529Sdas#define TIMER_RELTIME	0x0	/* relative timer */
113144529Sdas#endif
114144529Sdas#define TIMER_ABSTIME	0x1	/* absolute timer */
115144529Sdas#endif /* !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 200112 */
116144529Sdas
1171539Srgrimesstruct tm {
1181539Srgrimes	int	tm_sec;		/* seconds after the minute [0-60] */
1191539Srgrimes	int	tm_min;		/* minutes after the hour [0-59] */
1201539Srgrimes	int	tm_hour;	/* hours since midnight [0-23] */
1211539Srgrimes	int	tm_mday;	/* day of the month [1-31] */
1221539Srgrimes	int	tm_mon;		/* months since January [0-11] */
1231539Srgrimes	int	tm_year;	/* years since 1900 */
1241539Srgrimes	int	tm_wday;	/* days since Sunday [0-6] */
1251539Srgrimes	int	tm_yday;	/* days since January 1 [0-365] */
1261539Srgrimes	int	tm_isdst;	/* Daylight Savings Time flag */
12775033Sphk	long	tm_gmtoff;	/* offset from UTC in seconds */
1281539Srgrimes	char	*tm_zone;	/* timezone abbreviation */
1291539Srgrimes};
1301539Srgrimes
13198269Swollman#if __POSIX_VISIBLE
13238464Sjkoshyextern char *tzname[];
13338464Sjkoshy#endif
13438464Sjkoshy
1351539Srgrimes__BEGIN_DECLS
13693032Simpchar *asctime(const struct tm *);
13793032Simpclock_t clock(void);
13893032Simpchar *ctime(const time_t *);
13993032Simpdouble difftime(time_t, time_t);
140144529Sdas/* XXX missing: getdate() */
14193032Simpstruct tm *gmtime(const time_t *);
14293032Simpstruct tm *localtime(const time_t *);
14393032Simptime_t mktime(struct tm *);
144103012Stjrsize_t strftime(char * __restrict, size_t, const char * __restrict,
145103012Stjr    const struct tm * __restrict);
14693032Simptime_t time(time_t *);
147151870Sdavidxu#if __POSIX_VISIBLE >= 200112
148151870Sdavidxustruct sigevent;
149151870Sdavidxuint timer_create(clockid_t, struct sigevent *__restrict, timer_t *__restrict);
150151870Sdavidxuint timer_delete(timer_t);
151151870Sdavidxuint timer_gettime(timer_t, struct itimerspec *);
152151870Sdavidxuint timer_getoverrun(timer_t);
153151870Sdavidxuint timer_settime(timer_t, int, const struct itimerspec *__restrict,
154151870Sdavidxu	struct itimerspec *__restrict);
155151870Sdavidxu#endif
15698269Swollman#if __POSIX_VISIBLE
15793032Simpvoid tzset(void);
15898269Swollman#endif
15998269Swollman
16098923Swollman#if __POSIX_VISIBLE >= 199309
16198923Swollmanint clock_getres(clockid_t, struct timespec *);
16298923Swollmanint clock_gettime(clockid_t, struct timespec *);
16398923Swollmanint clock_settime(clockid_t, const struct timespec *);
164144529Sdas/* XXX missing: clock_nanosleep() */
16598923Swollmanint nanosleep(const struct timespec *, struct timespec *);
16698923Swollman#endif /* __POSIX_VISIBLE >= 199309 */
16798923Swollman
16898930Swollman#if __POSIX_VISIBLE >= 199506
16998930Swollmanchar *asctime_r(const struct tm *, char *);
17098930Swollmanchar *ctime_r(const time_t *, char *);
17198930Swollmanstruct tm *gmtime_r(const time_t *, struct tm *);
17298930Swollmanstruct tm *localtime_r(const time_t *, struct tm *);
17398930Swollman#endif
17498930Swollman
17598269Swollman#if __XSI_VISIBLE
176103012Stjrchar *strptime(const char * __restrict, const char * __restrict,
177103012Stjr    struct tm * __restrict);
17898269Swollman#endif
17998269Swollman
18098269Swollman#if __BSD_VISIBLE
181144529Sdaschar *timezone(int, int);	/* XXX XSI conflict */
18293032Simpvoid tzsetwall(void);
18393032Simptime_t timelocal(struct tm * const);
18493032Simptime_t timegm(struct tm * const);
18598269Swollman#endif /* __BSD_VISIBLE */
186232498Stheraven
187233600Stheraven#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_)
188232498Stheraven#include <xlocale/_time.h>
189232498Stheraven#endif
1901539Srgrimes__END_DECLS
1911539Srgrimes
1921539Srgrimes#endif /* !_TIME_H_ */
193