1/*
2 * Copyright 2005-2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _TIME_H_
6#define _TIME_H_
7
8
9#include <sys/types.h>
10
11
12struct sigevent;	/* defined in <signal.h> */
13
14
15typedef __haiku_int32 clock_t;
16typedef __haiku_int32 time_t;
17typedef __haiku_int32 suseconds_t;
18typedef __haiku_uint32 useconds_t;
19
20
21#define CLOCKS_PER_SEC	1000000
22#define CLK_TCK			CLOCKS_PER_SEC
23
24#define MAX_TIMESTR		70
25	/* maximum length of a string returned by asctime(), and ctime() */
26
27#define CLOCK_MONOTONIC				((clockid_t)0)
28	/* system-wide monotonic clock (aka system time) */
29#define CLOCK_REALTIME				((clockid_t)-1)
30	/* system-wide real time clock */
31#define CLOCK_PROCESS_CPUTIME_ID	((clockid_t)-2)
32	/* clock measuring the used CPU time of the current process */
33#define CLOCK_THREAD_CPUTIME_ID		((clockid_t)-3)
34	/* clock measuring the used CPU time of the current thread */
35
36#define TIMER_ABSTIME				1	/* absolute timer flag */
37
38
39struct timespec {
40	time_t	tv_sec;		/* seconds */
41	long	tv_nsec;	/* and nanoseconds */
42};
43
44struct itimerspec {
45	struct timespec it_interval;
46	struct timespec it_value;
47};
48
49struct tm {
50	int	tm_sec;
51	int	tm_min;
52	int	tm_hour;
53	int	tm_mday;	/* day of month (1 to 31) */
54	int	tm_mon;		/* months since January (0 to 11) */
55	int	tm_year;	/* years since 1900 */
56	int	tm_wday;	/* days since Sunday (0 to 6, Sunday = 0, ...) */
57	int	tm_yday;	/* days since January 1 (0 to 365) */
58	int	tm_isdst;	/* daylight savings time (0 == no, >0 == yes, <0 == has to be calculated */
59	int tm_gmtoff;	/* timezone offset to GMT */
60	char *tm_zone;	/* timezone name */
61};
62
63
64/* special timezone support */
65extern char *tzname[2];
66extern int 	daylight;
67extern long	timezone;
68
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74extern clock_t		clock(void);
75extern double		difftime(time_t time1, time_t time2);
76extern time_t		mktime(struct tm *tm);
77extern time_t		time(time_t *timer);
78extern char			*asctime(const struct tm *tm);
79extern char			*asctime_r(const struct tm *timep, char *buffer);
80extern char			*ctime(const time_t *timer);
81extern char			*ctime_r(const time_t *timer, char *buffer);
82extern struct tm	*gmtime(const time_t *timer);
83extern struct tm	*gmtime_r(const time_t *timer, struct tm *tm);
84extern struct tm	*localtime(const time_t *timer);
85extern struct tm	*localtime_r(const time_t *timer, struct tm *tm);
86extern int			nanosleep(const struct timespec *, struct timespec *);
87extern size_t		strftime(char *buffer, size_t maxSize, const char *format,
88						const struct tm *tm);
89extern char 		*strptime(const char *buf, const char *format, struct tm *tm);
90
91/* clock functions */
92int		clock_getres(clockid_t clockID, struct timespec* resolution);
93int		clock_gettime(clockid_t clockID, struct timespec* _time);
94int		clock_settime(clockid_t clockID, const struct timespec* _time);
95int		clock_nanosleep(clockid_t clockID, int flags,
96			const struct timespec* _time, struct timespec* remainingTime);
97int		clock_getcpuclockid(pid_t pid, clockid_t* _clockID);
98
99/* timer functions */
100int		timer_create(clockid_t clockID, struct sigevent* event,
101			timer_t* timerID);
102int		timer_delete(timer_t timerID);
103int		timer_gettime(timer_t timerID, struct itimerspec* value);
104int		timer_settime(timer_t timerID, int flags,
105			const struct itimerspec* value, struct itimerspec* oldValue);
106int		timer_getoverrun(timer_t timerID);
107
108/* special timezone support */
109extern void tzset(void);
110
111/* non-POSIX */
112extern int	stime(const time_t *t);
113
114#ifdef __cplusplus
115}
116#endif
117
118
119#endif	/* _TIME_H_ */
120