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 time_t; 17 typedef __haiku_int32 suseconds_t; 18 typedef __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 39 struct timespec { 40 time_t tv_sec; /* seconds */ 41 long tv_nsec; /* and nanoseconds */ 42 }; 43 44 struct itimerspec { 45 struct timespec it_interval; 46 struct timespec it_value; 47 }; 48 49 struct 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 */ 65 extern char *tzname[2]; 66 extern int daylight; 67 extern long timezone; 68 69 70 #ifdef __cplusplus 71 extern "C" { 72 #endif 73 74 extern clock_t clock(void); 75 extern double difftime(time_t time1, time_t time2); 76 extern time_t mktime(struct tm *tm); 77 extern time_t time(time_t *timer); 78 extern char *asctime(const struct tm *tm); 79 extern char *asctime_r(const struct tm *timep, char *buffer); 80 extern char *ctime(const time_t *timer); 81 extern char *ctime_r(const time_t *timer, char *buffer); 82 extern struct tm *gmtime(const time_t *timer); 83 extern struct tm *gmtime_r(const time_t *timer, struct tm *tm); 84 extern struct tm *localtime(const time_t *timer); 85 extern struct tm *localtime_r(const time_t *timer, struct tm *tm); 86 extern int nanosleep(const struct timespec *, struct timespec *); 87 extern size_t strftime(char *buffer, size_t maxSize, const char *format, 88 const struct tm *tm); 89 extern char *strptime(const char *buf, const char *format, struct tm *tm); 90 91 /* clock functions */ 92 int clock_getres(clockid_t clockID, struct timespec* resolution); 93 int clock_gettime(clockid_t clockID, struct timespec* time); 94 int clock_settime(clockid_t clockID, const struct timespec* time); 95 int clock_nanosleep(clockid_t clockID, int flags, 96 const struct timespec* time, struct timespec* remainingTime); 97 int clock_getcpuclockid(pid_t pid, clockid_t* _clockID); 98 99 /* timer functions */ 100 int timer_create(clockid_t clockID, struct sigevent* event, 101 timer_t* timerID); 102 int timer_delete(timer_t timerID); 103 int timer_gettime(timer_t timerID, struct itimerspec* value); 104 int timer_settime(timer_t timerID, int flags, 105 const struct itimerspec* value, struct itimerspec* oldValue); 106 int timer_getoverrun(timer_t timerID); 107 108 /* special timezone support */ 109 extern void tzset(void); 110 111 /* non-POSIX */ 112 extern int stime(const time_t *t); 113 114 #ifdef __cplusplus 115 } 116 #endif 117 118 119 #endif /* _TIME_H_ */ 120