1 /** 2 * D header file for POSIX. 3 * 4 * Copyright: Public Domain 5 * License: Public Domain 6 * Authors: Sean Kelly 7 * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition 8 */ 9 module tango.stdc.posix.time; 10 11 private import tango.stdc.posix.config; 12 public import tango.stdc.time; 13 public import tango.stdc.posix.sys.types; 14 public import tango.stdc.posix.signal; // for sigevent 15 16 extern (C): 17 18 // 19 // Required (defined in tango.stdc.time) 20 // 21 /* 22 char* asctime(in tm*); 23 clock_t clock(); 24 char* ctime(in time_t*); 25 double difftime(time_t, time_t); 26 tm* gmtime(in time_t*); 27 tm* localtime(in time_t*); 28 time_t mktime(tm*); 29 size_t strftime(char*, size_t, in char*, in tm*); 30 time_t time(time_t*); 31 */ 32 33 version( linux ) 34 { 35 time_t timegm(tm*); // non-standard 36 } 37 else version( darwin ) 38 { 39 time_t timegm(tm*); // non-standard 40 } 41 else version( FreeBSD ) 42 { 43 time_t timegm(tm*); // non-standard 44 } 45 else version( solaris ) 46 { 47 time_t timegm(tm* t) // non-standard 48 { 49 time_t tl, tb; 50 tm *tg; 51 52 tl = mktime (t); 53 if (tl == -1) 54 { 55 t.tm_hour--; 56 tl = mktime (t); 57 if (tl == -1) 58 return -1; /* can't deal with output from strptime */ 59 tl += 3600; 60 } 61 tg = gmtime (&tl); 62 tg.tm_isdst = 0; 63 tb = mktime (tg); 64 if (tb == -1) 65 { 66 tg.tm_hour--; 67 tb = mktime (tg); 68 if (tb == -1) 69 return -1; /* can't deal with output from gmtime */ 70 tb += 3600; 71 } 72 return (tl - (tb - tl)); 73 } 74 } 75 76 // 77 // C Extension (CX) 78 // (defined in tango.stdc.time) 79 // 80 /* 81 char* tzname[]; 82 void tzset(); 83 */ 84 85 // 86 // Process CPU-Time Clocks (CPT) 87 // 88 /* 89 int clock_getcpuclockid(pid_t, clockid_t*); 90 */ 91 92 // 93 // Clock Selection (CS) 94 // 95 /* 96 int clock_nanosleep(clockid_t, int, in timespec*, timespec*); 97 */ 98 99 // 100 // Monotonic Clock (MON) 101 // 102 /* 103 CLOCK_MONOTONIC 104 */ 105 106 // 107 // Timer (TMR) 108 // 109 /* 110 CLOCK_PROCESS_CPUTIME_ID (TMR|CPT) 111 CLOCK_THREAD_CPUTIME_ID (TMR|TCT) 112 113 NOTE: timespec must be defined in tango.stdc.posix.signal to break 114 a circular import. 115 116 struct timespec 117 { 118 time_t tv_sec; 119 int tv_nsec; 120 } 121 122 struct itimerspec 123 { 124 timespec it_interval; 125 timespec it_value; 126 } 127 128 CLOCK_REALTIME 129 TIMER_ABSTIME 130 131 clockid_t 132 timer_t 133 134 int clock_getres(clockid_t, timespec*); 135 int clock_gettime(clockid_t, timespec*); 136 int clock_settime(clockid_t, in timespec*); 137 int nanosleep(in timespec*, timespec*); 138 int timer_create(clockid_t, sigevent*, timer_t*); 139 int timer_delete(timer_t); 140 int timer_gettime(timer_t, itimerspec*); 141 int timer_getoverrun(timer_t); 142 int timer_settime(timer_t, int, in itimerspec*, itimerspec*); 143 */ 144 145 version( linux ) 146 { 147 const CLOCK_PROCESS_CPUTIME_ID = 2; // (TMR|CPT) 148 const CLOCK_THREAD_CPUTIME_ID = 3; // (TMR|TCT) 149 150 // NOTE: See above for why this is commented out. 151 // 152 //struct timespec 153 //{ 154 // time_t tv_sec; 155 // c_long tv_nsec; 156 //} 157 158 struct itimerspec 159 { 160 timespec it_interval; 161 timespec it_value; 162 } 163 164 const CLOCK_REALTIME = 0; 165 const TIMER_ABSTIME = 0x01; 166 167 alias int clockid_t; 168 alias int timer_t; 169 170 int clock_getres(clockid_t, timespec*); 171 //int clock_gettime(clockid_t, timespec*); 172 //int clock_settime(clockid_t, in timespec*); 173 int nanosleep(in timespec*, timespec*); 174 int timer_create(clockid_t, sigevent*, timer_t*); 175 int timer_delete(timer_t); 176 int timer_gettime(timer_t, itimerspec*); 177 int timer_getoverrun(timer_t); 178 int timer_settime(timer_t, int, in itimerspec*, itimerspec*); 179 } 180 else version( darwin ) 181 { 182 int nanosleep(in timespec*, timespec*); 183 } 184 else version( FreeBSD ) 185 { 186 const CLOCK_PROCESS_CPUTIME_ID = 2; // (TMR|CPT) 187 const CLOCK_THREAD_CPUTIME_ID = 3; // (TMR|TCT) 188 189 // NOTE: See above for why this is commented out. 190 // 191 //struct timespec 192 //{ 193 // time_t tv_sec; 194 // c_long tv_nsec; 195 //} 196 197 struct itimerspec 198 { 199 timespec it_interval; 200 timespec it_value; 201 } 202 203 const CLOCK_REALTIME = 0; 204 const TIMER_ABSTIME = 0x01; 205 206 alias int clockid_t; 207 alias int timer_t; 208 209 int clock_getres(clockid_t, timespec*); 210 int clock_gettime(clockid_t, timespec*); 211 int clock_settime(clockid_t, in timespec*); 212 int nanosleep(in timespec*, timespec*); 213 int timer_create(clockid_t, sigevent*, timer_t*); 214 int timer_delete(timer_t); 215 int timer_gettime(timer_t, itimerspec*); 216 int timer_getoverrun(timer_t); 217 int timer_settime(timer_t, int, in itimerspec*, itimerspec*); 218 } 219 else version( solaris ) 220 { 221 const CLOCK_PROCESS_CPUTIME_ID = 5; // (TMR|CPT) 222 const CLOCK_THREAD_CPUTIME_ID = 2; // (TMR|TCT) 223 224 // NOTE: See above for why this is commented out. 225 // 226 //struct timespec 227 //{ 228 // time_t tv_sec; 229 // c_long tv_nsec; 230 //} 231 232 struct itimerspec 233 { 234 timespec it_interval; 235 timespec it_value; 236 } 237 238 const CLOCK_REALTIME = 3; 239 const TIMER_ABSTIME = 0x1; 240 241 alias int clockid_t; 242 alias int timer_t; 243 244 int clock_getres(clockid_t, timespec*); 245 int clock_gettime(clockid_t, timespec*); 246 int clock_settime(clockid_t, in timespec*); 247 int nanosleep(in timespec*, timespec*); 248 int timer_create(clockid_t, sigevent*, timer_t*); 249 int timer_delete(timer_t); 250 int timer_gettime(timer_t, itimerspec*); 251 int timer_getoverrun(timer_t); 252 int timer_settime(timer_t, int, in itimerspec*, itimerspec*); 253 } 254 255 256 // 257 // Thread-Safe Functions (TSF) 258 // 259 /* 260 char* asctime_r(in tm*, char*); 261 char* ctime_r(in time_t*, char*); 262 tm* gmtime_r(in time_t*, tm*); 263 tm* localtime_r(in time_t*, tm*); 264 */ 265 266 version( linux ) 267 { 268 char* asctime_r(in tm*, char*); 269 char* ctime_r(in time_t*, char*); 270 tm* gmtime_r(in time_t*, tm*); 271 tm* localtime_r(in time_t*, tm*); 272 } 273 else version( darwin ) 274 { 275 char* asctime_r(in tm*, char*); 276 char* ctime_r(in time_t*, char*); 277 tm* gmtime_r(in time_t*, tm*); 278 tm* localtime_r(in time_t*, tm*); 279 } 280 else version( FreeBSD ) 281 { 282 char* asctime_r(in tm*, char*); 283 char* ctime_r(in time_t*, char*); 284 tm* gmtime_r(in time_t*, tm*); 285 tm* localtime_r(in time_t*, tm*); 286 } 287 else version( solaris ) 288 { 289 char* asctime_r(in tm*, char*); 290 char* ctime_r(in time_t*, char*); 291 tm* gmtime_r(in time_t*, tm*); 292 tm* localtime_r(in time_t*, tm*); 293 } 294 295 // 296 // XOpen (XSI) 297 // 298 /* 299 getdate_err 300 301 int daylight; 302 int timezone; 303 304 tm* getdate(in char*); 305 char* strptime(in char*, in char*, tm*); 306 */ 307 308 version( linux ) 309 { 310 extern __gshared int daylight; 311 extern __gshared c_long timezone; 312 313 tm* getdate(in char*); 314 char* strptime(in char*, in char*, tm*); 315 } 316 else version( darwin ) 317 { 318 extern __gshared c_long timezone; 319 320 tm* getdate(in char*); 321 char* strptime(in char*, in char*, tm*); 322 } 323 else version( FreeBSD ) 324 { 325 extern __gshared c_long timezone; 326 327 //tm* getdate(in char*); 328 char* strptime(in char*, in char*, tm*); 329 } 330 else version( solaris ) 331 { 332 extern __gshared c_long timezone; 333 334 tm* getdate(in char*); 335 char* strptime(in char*, in char*, tm*); 336 }