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