vfs: check userland buffers before reading them.
[haiku.git] / headers / posix / time.h
blob8ee6a61dfa932b0b96e0a5bbfdb5ed4a66ad258c
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_
9 #include <sys/types.h>
12 struct sigevent; /* defined in <signal.h> */
15 typedef __haiku_int32 clock_t;
16 typedef __haiku_int32 suseconds_t;
17 typedef __haiku_uint32 useconds_t;
19 #if defined(__i386__) && !defined(__x86_64__)
20 typedef __haiku_int32 time_t;
21 #else
22 typedef __haiku_int64 time_t;
23 #endif
26 #define CLOCKS_PER_SEC 1000000
27 #define CLK_TCK CLOCKS_PER_SEC
29 #define MAX_TIMESTR 70
30 /* maximum length of a string returned by asctime(), and ctime() */
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 */
41 #define TIMER_ABSTIME 1 /* absolute timer flag */
44 struct timespec {
45 time_t tv_sec; /* seconds */
46 long tv_nsec; /* and nanoseconds */
49 struct itimerspec {
50 struct timespec it_interval;
51 struct timespec it_value;
54 struct 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 */
69 /* special timezone support */
70 extern char *tzname[2];
71 extern int daylight;
72 extern long timezone;
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
79 extern clock_t clock(void);
80 extern double difftime(time_t time1, time_t time2);
81 extern time_t mktime(struct tm *tm);
82 extern time_t time(time_t *timer);
83 extern char *asctime(const struct tm *tm);
84 extern char *asctime_r(const struct tm *timep, char *buffer);
85 extern char *ctime(const time_t *timer);
86 extern char *ctime_r(const time_t *timer, char *buffer);
87 extern struct tm *gmtime(const time_t *timer);
88 extern struct tm *gmtime_r(const time_t *timer, struct tm *tm);
89 extern struct tm *localtime(const time_t *timer);
90 extern struct tm *localtime_r(const time_t *timer, struct tm *tm);
91 extern int nanosleep(const struct timespec *, struct timespec *);
92 extern size_t strftime(char *buffer, size_t maxSize, const char *format,
93 const struct tm *tm);
94 extern char *strptime(const char *buf, const char *format, struct tm *tm);
96 /* clock functions */
97 int clock_getres(clockid_t clockID, struct timespec* resolution);
98 int clock_gettime(clockid_t clockID, struct timespec* _time);
99 int clock_settime(clockid_t clockID, const struct timespec* _time);
100 int clock_nanosleep(clockid_t clockID, int flags,
101 const struct timespec* _time, struct timespec* remainingTime);
102 int clock_getcpuclockid(pid_t pid, clockid_t* _clockID);
104 /* timer functions */
105 int timer_create(clockid_t clockID, struct sigevent* event,
106 timer_t* timerID);
107 int timer_delete(timer_t timerID);
108 int timer_gettime(timer_t timerID, struct itimerspec* value);
109 int timer_settime(timer_t timerID, int flags,
110 const struct itimerspec* value, struct itimerspec* oldValue);
111 int timer_getoverrun(timer_t timerID);
113 /* special timezone support */
114 extern void tzset(void);
116 /* non-POSIX */
117 extern int stime(const time_t *t);
119 #ifdef __cplusplus
121 #endif
124 #endif /* _TIME_H_ */