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