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 13 struct sigevent; /* defined in <signal.h> */ 14 15 16 typedef __haiku_int32 clock_t; 17 typedef __haiku_int32 suseconds_t; 18 typedef __haiku_uint32 useconds_t; 19 20 #if defined(__i386__) && !defined(__x86_64__) 21 typedef __haiku_int32 time_t; 22 #else 23 typedef __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 46 struct timespec { 47 time_t tv_sec; /* seconds */ 48 long tv_nsec; /* and nanoseconds */ 49 }; 50 51 struct itimerspec { 52 struct timespec it_interval; 53 struct timespec it_value; 54 }; 55 56 struct 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 */ 72 extern char *tzname[2]; 73 extern int daylight; 74 extern long timezone; 75 76 77 #ifdef __cplusplus 78 extern "C" { 79 #endif 80 81 extern clock_t clock(void); 82 extern double difftime(time_t time1, time_t time2); 83 extern time_t mktime(struct tm *tm); 84 extern time_t time(time_t *timer); 85 extern char *asctime(const struct tm *tm); 86 extern char *asctime_r(const struct tm *timep, char *buffer); 87 extern char *ctime(const time_t *timer); 88 extern char *ctime_r(const time_t *timer, char *buffer); 89 extern struct tm *gmtime(const time_t *timer); 90 extern struct tm *gmtime_r(const time_t *timer, struct tm *tm); 91 extern struct tm *localtime(const time_t *timer); 92 extern struct tm *localtime_r(const time_t *timer, struct tm *tm); 93 extern int nanosleep(const struct timespec *, struct timespec *); 94 extern size_t strftime(char *buffer, size_t maxSize, const char *format, 95 const struct tm *tm); 96 extern size_t strftime_l(char *buffer, size_t maxSize, const char *format, 97 const struct tm *tm, locale_t locale); 98 extern char *strptime(const char *buf, const char *format, struct tm *tm); 99 100 /* clock functions */ 101 int clock_getres(clockid_t clockID, struct timespec* resolution); 102 int clock_gettime(clockid_t clockID, struct timespec* _time); 103 int clock_settime(clockid_t clockID, const struct timespec* _time); 104 int clock_nanosleep(clockid_t clockID, int flags, 105 const struct timespec* _time, struct timespec* remainingTime); 106 int clock_getcpuclockid(pid_t pid, clockid_t* _clockID); 107 108 /* timer functions */ 109 int timer_create(clockid_t clockID, struct sigevent* event, 110 timer_t* timerID); 111 int timer_delete(timer_t timerID); 112 int timer_gettime(timer_t timerID, struct itimerspec* value); 113 int timer_settime(timer_t timerID, int flags, 114 const struct itimerspec* value, struct itimerspec* oldValue); 115 int timer_getoverrun(timer_t timerID); 116 117 /* C11 timespec */ 118 int timespec_get(struct timespec *ts, int base); 119 120 /* special timezone support */ 121 extern void tzset(void); 122 123 /* non-POSIX */ 124 extern int stime(const time_t *t); 125 126 #ifdef __cplusplus 127 } 128 #endif 129 130 131 #endif /* _TIME_H_ */ 132