1199767fToomas Soome/*
2199767fToomas Soome * Copyright (c) 1989, 1993
3199767fToomas Soome *	The Regents of the University of California.  All rights reserved.
4199767fToomas Soome * (c) UNIX System Laboratories, Inc.
5199767fToomas Soome * All or some portions of this file are derived from material licensed
6199767fToomas Soome * to the University of California by American Telephone and Telegraph
7199767fToomas Soome * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8199767fToomas Soome * the permission of UNIX System Laboratories, Inc.
9199767fToomas Soome *
10199767fToomas Soome * Redistribution and use in source and binary forms, with or without
11199767fToomas Soome * modification, are permitted provided that the following conditions
12199767fToomas Soome * are met:
13199767fToomas Soome * 1. Redistributions of source code must retain the above copyright
14199767fToomas Soome *    notice, this list of conditions and the following disclaimer.
15199767fToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
16199767fToomas Soome *    notice, this list of conditions and the following disclaimer in the
17199767fToomas Soome *    documentation and/or other materials provided with the distribution.
18199767fToomas Soome * 3. Neither the name of the University nor the names of its contributors
19199767fToomas Soome *    may be used to endorse or promote products derived from this software
20199767fToomas Soome *    without specific prior written permission.
21199767fToomas Soome *
22199767fToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23199767fToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24199767fToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25199767fToomas Soome * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26199767fToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27199767fToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28199767fToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29199767fToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30199767fToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31199767fToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32199767fToomas Soome * SUCH DAMAGE.
33199767fToomas Soome *
34199767fToomas Soome *	@(#)time.h	8.3 (Berkeley) 1/21/94
35199767fToomas Soome */
36199767fToomas Soome
37199767fToomas Soome/*
38199767fToomas Soome * $FreeBSD$
39199767fToomas Soome */
40199767fToomas Soome
41199767fToomas Soome#ifndef _TIME_H_
42199767fToomas Soome#define	_TIME_H_
43199767fToomas Soome
44199767fToomas Soome#include <sys/cdefs.h>
45199767fToomas Soome#include <sys/_null.h>
46199767fToomas Soome#include <sys/_types.h>
47199767fToomas Soome
48199767fToomas Soome#if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE
49199767fToomas Soome/*
50199767fToomas Soome * Frequency of the clock ticks reported by times().  Deprecated - use
51199767fToomas Soome * sysconf(_SC_CLK_TCK) instead.  (Removed in 1003.1-2001.)
52199767fToomas Soome */
53199767fToomas Soome#define	CLK_TCK		128
54199767fToomas Soome#endif
55199767fToomas Soome
56199767fToomas Soome/* Frequency of the clock ticks reported by clock().  */
57199767fToomas Soome#define	CLOCKS_PER_SEC	128
58199767fToomas Soome
59199767fToomas Soome#ifndef _CLOCK_T_DECLARED
60199767fToomas Soometypedef	__clock_t	clock_t;
61199767fToomas Soome#define	_CLOCK_T_DECLARED
62199767fToomas Soome#endif
63199767fToomas Soome
64199767fToomas Soome#ifndef _TIME_T_DECLARED
65199767fToomas Soometypedef	__time_t	time_t;
66199767fToomas Soome#define	_TIME_T_DECLARED
67199767fToomas Soome#endif
68199767fToomas Soome
69199767fToomas Soome#ifndef _SIZE_T_DECLARED
70199767fToomas Soometypedef	__size_t	size_t;
71199767fToomas Soome#define	_SIZE_T_DECLARED
72199767fToomas Soome#endif
73199767fToomas Soome
74199767fToomas Soome#if __POSIX_VISIBLE >= 199309
75199767fToomas Soome/*
76199767fToomas Soome * New in POSIX 1003.1b-1993.
77199767fToomas Soome */
78199767fToomas Soome#ifndef _CLOCKID_T_DECLARED
79199767fToomas Soometypedef	__clockid_t	clockid_t;
80199767fToomas Soome#define	_CLOCKID_T_DECLARED
81199767fToomas Soome#endif
82199767fToomas Soome
83199767fToomas Soome#ifndef _TIMER_T_DECLARED
84199767fToomas Soometypedef	__timer_t	timer_t;
85199767fToomas Soome#define	_TIMER_T_DECLARED
86199767fToomas Soome#endif
87199767fToomas Soome
88199767fToomas Soome#include <sys/timespec.h>
89199767fToomas Soome#endif /* __POSIX_VISIBLE >= 199309 */
90199767fToomas Soome
91199767fToomas Soome#if __POSIX_VISIBLE >= 200112
92199767fToomas Soome#ifndef _PID_T_DECLARED
93199767fToomas Soometypedef	__pid_t		pid_t;
94199767fToomas Soome#define	_PID_T_DECLARED
95199767fToomas Soome#endif
96199767fToomas Soome#endif
97199767fToomas Soome
98199767fToomas Soome/* These macros are also in sys/time.h. */
99199767fToomas Soome#if !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 200112
100199767fToomas Soome#define CLOCK_REALTIME	0
101199767fToomas Soome#ifdef __BSD_VISIBLE
102199767fToomas Soome#define CLOCK_VIRTUAL	1
103199767fToomas Soome#define CLOCK_PROF	2
104199767fToomas Soome#endif
105199767fToomas Soome#define CLOCK_MONOTONIC	4
106199767fToomas Soome#define CLOCK_UPTIME	5		/* FreeBSD-specific. */
107199767fToomas Soome#define CLOCK_UPTIME_PRECISE	7	/* FreeBSD-specific. */
108199767fToomas Soome#define CLOCK_UPTIME_FAST	8	/* FreeBSD-specific. */
109199767fToomas Soome#define CLOCK_REALTIME_PRECISE	9	/* FreeBSD-specific. */
110199767fToomas Soome#define CLOCK_REALTIME_FAST	10	/* FreeBSD-specific. */
111199767fToomas Soome#define CLOCK_MONOTONIC_PRECISE	11	/* FreeBSD-specific. */
112199767fToomas Soome#define CLOCK_MONOTONIC_FAST	12	/* FreeBSD-specific. */
113199767fToomas Soome#define CLOCK_SECOND	13		/* FreeBSD-specific. */
114199767fToomas Soome#define CLOCK_THREAD_CPUTIME_ID	14
115199767fToomas Soome#define	CLOCK_PROCESS_CPUTIME_ID	15
116199767fToomas Soome#endif /* !defined(CLOCK_REALTIME) && __POSIX_VISIBLE >= 200112 */
117199767fToomas Soome
118199767fToomas Soome#if !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 200112
119199767fToomas Soome#if __BSD_VISIBLE
120199767fToomas Soome#define TIMER_RELTIME	0x0	/* relative timer */
121199767fToomas Soome#endif
122199767fToomas Soome#define TIMER_ABSTIME	0x1	/* absolute timer */
123199767fToomas Soome#endif /* !defined(TIMER_ABSTIME) && __POSIX_VISIBLE >= 200112 */
124199767fToomas Soome
125199767fToomas Soomestruct tm {
126199767fToomas Soome	int	tm_sec;		/* seconds after the minute [0-60] */
127199767fToomas Soome	int	tm_min;		/* minutes after the hour [0-59] */
128199767fToomas Soome	int	tm_hour;	/* hours since midnight [0-23] */
129199767fToomas Soome	int	tm_mday;	/* day of the month [1-31] */
130199767fToomas Soome	int	tm_mon;		/* months since January [0-11] */
131199767fToomas Soome	int	tm_year;	/* years since 1900 */
132199767fToomas Soome	int	tm_wday;	/* days since Sunday [0-6] */
133199767fToomas Soome	int	tm_yday;	/* days since January 1 [0-365] */
134199767fToomas Soome	int	tm_isdst;	/* Daylight Savings Time flag */
135199767fToomas Soome	long	tm_gmtoff;	/* offset from UTC in seconds */
136199767fToomas Soome	char	*tm_zone;	/* timezone abbreviation */
137199767fToomas Soome};
138199767fToomas Soome
139199767fToomas Soome#if __POSIX_VISIBLE
140199767fToomas Soomeextern char *tzname[];
141199767fToomas Soome#endif
142199767fToomas Soome
143199767fToomas Soome__BEGIN_DECLS
144199767fToomas Soomechar *asctime(const struct tm *);
145199767fToomas Soomeclock_t clock(void);
146199767fToomas Soomechar *ctime(const time_t *);
147199767fToomas Soomedouble difftime(time_t, time_t);
148199767fToomas Soome/* XXX missing: getdate() */
149199767fToomas Soomestruct tm *gmtime(const time_t *);
150199767fToomas Soomestruct tm *localtime(const time_t *);
151199767fToomas Soometime_t mktime(struct tm *);
152199767fToomas Soomesize_t strftime(char * __restrict, size_t, const char * __restrict,
153199767fToomas Soome    const struct tm * __restrict);
154199767fToomas Soometime_t time(time_t *);
155199767fToomas Soome#if __POSIX_VISIBLE >= 200112
156199767fToomas Soomestruct sigevent;
157199767fToomas Soomeint timer_create(clockid_t, struct sigevent *__restrict, timer_t *__restrict);
158199767fToomas Soomeint timer_delete(timer_t);
159199767fToomas Soomeint timer_gettime(timer_t, struct itimerspec *);
160199767fToomas Soomeint timer_getoverrun(timer_t);
161199767fToomas Soomeint timer_settime(timer_t, int, const struct itimerspec *__restrict,
162199767fToomas Soome	struct itimerspec *__restrict);
163199767fToomas Soome#endif
164199767fToomas Soome#if __POSIX_VISIBLE
165199767fToomas Soomevoid tzset(void);
166199767fToomas Soome#endif
167199767fToomas Soome
168199767fToomas Soome#if __POSIX_VISIBLE >= 199309
169199767fToomas Soomeint clock_getres(clockid_t, struct timespec *);
170199767fToomas Soomeint clock_gettime(clockid_t, struct timespec *);
171199767fToomas Soomeint clock_settime(clockid_t, const struct timespec *);
172199767fToomas Soome/* XXX missing: clock_nanosleep() */
173199767fToomas Soomeint nanosleep(const struct timespec *, struct timespec *);
174199767fToomas Soome#endif /* __POSIX_VISIBLE >= 199309 */
175199767fToomas Soome
176199767fToomas Soome#if __POSIX_VISIBLE >= 200112
177199767fToomas Soomeint clock_getcpuclockid(pid_t, clockid_t *);
178199767fToomas Soome#endif
179199767fToomas Soome
180199767fToomas Soome#if __POSIX_VISIBLE >= 199506
181199767fToomas Soomechar *asctime_r(const struct tm *, char *);
182199767fToomas Soomechar *ctime_r(const time_t *, char *);
183199767fToomas Soomestruct tm *gmtime_r(const time_t *, struct tm *);
184199767fToomas Soomestruct tm *localtime_r(const time_t *, struct tm *);
185199767fToomas Soome#endif
186199767fToomas Soome
187199767fToomas Soome#if __XSI_VISIBLE
188199767fToomas Soomechar *strptime(const char * __restrict, const char * __restrict,
189199767fToomas Soome    struct tm * __restrict);
190199767fToomas Soome#endif
191199767fToomas Soome
192199767fToomas Soome#if __BSD_VISIBLE
193199767fToomas Soomechar *timezone(int, int);	/* XXX XSI conflict */
194199767fToomas Soomevoid tzsetwall(void);
195199767fToomas Soometime_t timelocal(struct tm * const);
196199767fToomas Soometime_t timegm(struct tm * const);
197199767fToomas Soome#endif /* __BSD_VISIBLE */
198199767fToomas Soome
199199767fToomas Soome#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_)
200199767fToomas Soome#include <xlocale/_time.h>
201199767fToomas Soome#endif
202199767fToomas Soome__END_DECLS
203199767fToomas Soome
204199767fToomas Soome#endif /* !_TIME_H_ */
205