1 /* 2 Copyright (c) 1991, 1993 3 The Regents of the University of California. All rights reserved. 4 c) UNIX System Laboratories, Inc. 5 All or some portions of this file are derived from material licensed 6 to the University of California by American Telephone and Telegraph 7 Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 the permission of UNIX System Laboratories, Inc. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions 12 are met: 13 1. Redistributions of source code must retain the above copyright 14 notice, this list of conditions and the following disclaimer. 15 2. Redistributions in binary form must reproduce the above copyright 16 notice, this list of conditions and the following disclaimer in the 17 documentation and/or other materials provided with the distribution. 18 3. Neither the name of the University nor the names of its contributors 19 may be used to endorse or promote products derived from this software 20 without specific prior written permission. 21 22 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 SUCH DAMAGE. 33 */ 34 /* 35 * time.h 36 * 37 * Struct and function declarations for dealing with time. 38 */ 39 40 #ifndef _TIME_H_ 41 #define _TIME_H_ 42 43 #include "_ansi.h" 44 #include <sys/cdefs.h> 45 46 #define __need_size_t 47 #define __need_NULL 48 #include <stddef.h> 49 50 /* Get _CLOCKS_PER_SEC_ */ 51 #include <machine/time.h> 52 53 #ifndef _CLOCKS_PER_SEC_ 54 #ifdef CLK_TCK 55 #define _CLOCKS_PER_SEC_ CLK_TCK 56 #else 57 #ifdef CLOCKS_PER_SEC 58 #define _CLOCKS_PER_SEC_ CLOCKS_PER_SEC 59 #else 60 #define _CLOCKS_PER_SEC_ 1000 61 #endif 62 #endif 63 #endif 64 65 #ifndef CLOCKS_PER_SEC 66 #define CLOCKS_PER_SEC _CLOCKS_PER_SEC_ 67 #endif 68 #ifndef CLK_TCK 69 #define CLK_TCK CLOCKS_PER_SEC 70 #endif 71 72 #include <sys/types.h> 73 #include <sys/timespec.h> 74 75 #if __POSIX_VISIBLE >= 200809 76 #include <sys/_locale.h> 77 #endif 78 79 _BEGIN_STD_C 80 81 struct tm 82 { 83 int tm_sec; 84 int tm_min; 85 int tm_hour; 86 int tm_mday; 87 int tm_mon; 88 int tm_year; 89 int tm_wday; 90 int tm_yday; 91 int tm_isdst; 92 #ifdef __TM_GMTOFF 93 long __TM_GMTOFF; 94 #endif 95 #ifdef __TM_ZONE 96 const char *__TM_ZONE; 97 #endif 98 }; 99 100 clock_t clock (void); 101 double difftime (time_t _time2, time_t _time1); 102 time_t mktime (struct tm *_timeptr); 103 #if __BSD_VISIBLE || __SVID_VISIBLE || __GNU_VISIBLE 104 time_t timegm (struct tm *_timeptr); 105 #endif 106 time_t time (time_t *_timer); 107 #ifndef _REENT_ONLY 108 char *asctime (const struct tm *_tblock); 109 char *ctime (const time_t *_time); 110 struct tm *gmtime (const time_t *_timer); 111 struct tm *localtime (const time_t *_timer); 112 #endif 113 size_t strftime (char *__restrict _s, 114 size_t _maxsize, const char *__restrict _fmt, 115 const struct tm *__restrict _t); 116 117 #if __POSIX_VISIBLE >= 200809 118 extern size_t strftime_l (char *__restrict _s, size_t _maxsize, 119 const char *__restrict _fmt, 120 const struct tm *__restrict _t, locale_t _l); 121 #endif 122 123 char *asctime_r (const struct tm *__restrict, 124 char *__restrict); 125 char *ctime_r (const time_t *, char *); 126 struct tm *gmtime_r (const time_t *__restrict, 127 struct tm *__restrict); 128 struct tm *localtime_r (const time_t *__restrict, 129 struct tm *__restrict); 130 131 _END_STD_C 132 133 #ifdef __cplusplus 134 extern "C" { 135 #endif 136 137 #if __XSI_VISIBLE 138 char *strptime (const char *__restrict, 139 const char *__restrict, 140 struct tm *__restrict); 141 #endif 142 #if __GNU_VISIBLE 143 char *strptime_l (const char *__restrict, const char *__restrict, 144 struct tm *__restrict, locale_t); 145 #endif 146 147 #if __POSIX_VISIBLE 148 void tzset (void); 149 #endif 150 151 /* getdate functions */ 152 153 #ifdef HAVE_GETDATE 154 #if __XSI_VISIBLE >= 4 155 #ifndef _REENT_ONLY 156 extern NEWLIB_THREAD_LOCAL int getdate_err; 157 158 struct tm * getdate (const char *); 159 /* getdate_err is set to one of the following values to indicate the error. 160 1 the DATEMSK environment variable is null or undefined, 161 2 the template file cannot be opened for reading, 162 3 failed to get file status information, 163 4 the template file is not a regular file, 164 5 an error is encountered while reading the template file, 165 6 memory allication failed (not enough memory available), 166 7 there is no line in the template that matches the input, 167 8 invalid input specification */ 168 #endif /* !_REENT_ONLY */ 169 #endif /* __XSI_VISIBLE >= 4 */ 170 171 #if __GNU_VISIBLE 172 /* getdate_r returns the error code as above */ 173 int getdate_r (const char *, struct tm *); 174 #endif /* __GNU_VISIBLE */ 175 #endif /* HAVE_GETDATE */ 176 177 /* defines for the opengroup specifications Derived from Issue 1 of the SVID. */ 178 #if __SVID_VISIBLE || __XSI_VISIBLE 179 extern __IMPORT long _timezone; 180 extern __IMPORT int _daylight; 181 #endif 182 #if __POSIX_VISIBLE 183 extern __IMPORT char *_tzname[2]; 184 185 /* POSIX defines the external tzname being defined in time.h */ 186 #ifndef tzname 187 #define tzname _tzname 188 #endif 189 #endif /* __POSIX_VISIBLE */ 190 191 #ifdef __cplusplus 192 } 193 #endif 194 195 #include <sys/features.h> 196 197 #ifdef __CYGWIN__ 198 #include <cygwin/time.h> 199 #endif /*__CYGWIN__*/ 200 201 #if defined(_POSIX_TIMERS) 202 203 #include <signal.h> 204 205 #ifdef __cplusplus 206 extern "C" { 207 #endif 208 209 /* Clocks, P1003.1b-1993, p. 263 */ 210 211 int clock_settime (clockid_t clock_id, const struct timespec *tp); 212 int clock_gettime (clockid_t clock_id, struct timespec *tp); 213 int clock_getres (clockid_t clock_id, struct timespec *res); 214 215 /* Create a Per-Process Timer, P1003.1b-1993, p. 264 */ 216 217 int timer_create (clockid_t clock_id, 218 struct sigevent *__restrict evp, 219 timer_t *__restrict timerid); 220 221 /* Delete a Per_process Timer, P1003.1b-1993, p. 266 */ 222 223 int timer_delete (timer_t timerid); 224 225 /* Per-Process Timers, P1003.1b-1993, p. 267 */ 226 227 int timer_settime (timer_t timerid, int flags, 228 const struct itimerspec *__restrict value, 229 struct itimerspec *__restrict ovalue); 230 int timer_gettime (timer_t timerid, struct itimerspec *value); 231 int timer_getoverrun (timer_t timerid); 232 233 /* High Resolution Sleep, P1003.1b-1993, p. 269 */ 234 235 int nanosleep (const struct timespec *rqtp, struct timespec *rmtp); 236 237 #ifdef __cplusplus 238 } 239 #endif 240 #endif /* _POSIX_TIMERS */ 241 242 #if defined(_POSIX_CLOCK_SELECTION) 243 244 #ifdef __cplusplus 245 extern "C" { 246 #endif 247 248 int clock_nanosleep (clockid_t clock_id, int flags, 249 const struct timespec *rqtp, struct timespec *rmtp); 250 251 #ifdef __cplusplus 252 } 253 #endif 254 255 #endif /* _POSIX_CLOCK_SELECTION */ 256 257 #ifdef __cplusplus 258 extern "C" { 259 #endif 260 261 /* CPU-time Clock Attributes, P1003.4b/D8, p. 54 */ 262 263 /* values for the clock enable attribute */ 264 265 #define CLOCK_ENABLED 1 /* clock is enabled, i.e. counting execution time */ 266 #define CLOCK_DISABLED 0 /* clock is disabled */ 267 268 /* values for the pthread cputime_clock_allowed attribute */ 269 270 #define CLOCK_ALLOWED 1 /* If a thread is created with this value a */ 271 /* CPU-time clock attached to that thread */ 272 /* shall be accessible. */ 273 #define CLOCK_DISALLOWED 0 /* If a thread is created with this value, the */ 274 /* thread shall not have a CPU-time clock */ 275 /* accessible. */ 276 277 /* Flag indicating time is "absolute" with respect to the clock 278 associated with a time. Value 4 is historic. */ 279 280 #define TIMER_ABSTIME 4 281 282 /* Manifest Constants, P1003.1b-1993, p. 262 */ 283 284 #if __GNU_VISIBLE 285 #define CLOCK_REALTIME_COARSE ((clockid_t) 0) 286 #endif 287 288 #define CLOCK_REALTIME ((clockid_t) 1) 289 290 /* Manifest Constants, P1003.4b/D8, p. 55 */ 291 292 #if defined(_POSIX_CPUTIME) 293 294 /* When used in a clock or timer function call, this is interpreted as 295 the identifier of the CPU_time clock associated with the PROCESS 296 making the function call. */ 297 298 #define CLOCK_PROCESS_CPUTIME_ID ((clockid_t) 2) 299 300 #endif 301 302 #if defined(_POSIX_THREAD_CPUTIME) 303 304 /* When used in a clock or timer function call, this is interpreted as 305 the identifier of the CPU_time clock associated with the THREAD 306 making the function call. */ 307 308 #define CLOCK_THREAD_CPUTIME_ID ((clockid_t) 3) 309 310 #endif 311 312 #if defined(_POSIX_MONOTONIC_CLOCK) 313 314 /* The identifier for the system-wide monotonic clock, which is defined 315 * as a clock whose value cannot be set via clock_settime() and which 316 * cannot have backward clock jumps. */ 317 318 #define CLOCK_MONOTONIC ((clockid_t) 4) 319 320 #endif 321 322 #if __GNU_VISIBLE 323 324 #define CLOCK_MONOTONIC_RAW ((clockid_t) 5) 325 326 #define CLOCK_MONOTONIC_COARSE ((clockid_t) 6) 327 328 #define CLOCK_BOOTTIME ((clockid_t) 7) 329 330 #define CLOCK_REALTIME_ALARM ((clockid_t) 8) 331 332 #define CLOCK_BOOTTIME_ALARM ((clockid_t) 9) 333 334 #endif 335 336 #if defined(_POSIX_CPUTIME) 337 338 /* Accessing a Process CPU-time CLock, P1003.4b/D8, p. 55 */ 339 340 int clock_getcpuclockid (pid_t pid, clockid_t *clock_id); 341 342 #endif /* _POSIX_CPUTIME */ 343 344 #if defined(_POSIX_CPUTIME) || defined(_POSIX_THREAD_CPUTIME) 345 346 /* CPU-time Clock Attribute Access, P1003.4b/D8, p. 56 */ 347 348 int clock_setenable_attr (clockid_t clock_id, int attr); 349 int clock_getenable_attr (clockid_t clock_id, int *attr); 350 351 #endif /* _POSIX_CPUTIME or _POSIX_THREAD_CPUTIME */ 352 353 #ifdef __cplusplus 354 } 355 #endif 356 357 #endif /* _TIME_H_ */ 358 359