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