1 /* Copyright (C) 1991-2003,2006,2009 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 4 The GNU C Library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 The GNU C Library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with the GNU C Library; if not, see 16 <http://www.gnu.org/licenses/>. */ 17 18 /* 19 * ISO C99 Standard: 7.23 Date and time <time.h> 20 */ 21 22 #ifndef _TIME_H 23 24 #if (! defined __need_time_t && !defined __need_clock_t && \ 25 ! defined __need_timespec) 26 # define _TIME_H 1 27 # include <features.h> 28 29 __BEGIN_DECLS 30 31 #endif 32 33 #ifdef _TIME_H 34 /* Get size_t and NULL from <stddef.h>. */ 35 # define __need_size_t 36 # define __need_NULL 37 # include <stddef.h> 38 39 /* This defines CLOCKS_PER_SEC, which is the number of processor clock 40 ticks per second. */ 41 # include <bits/time.h> 42 43 /* This is the obsolete POSIX.1-1988 name for the same constant. */ 44 # if !defined __STRICT_ANSI__ && !defined __USE_XOPEN2K 45 # ifndef CLK_TCK 46 # define CLK_TCK CLOCKS_PER_SEC 47 # endif 48 # endif 49 50 #endif /* <time.h> included. */ 51 52 #if !defined __clock_t_defined && (defined _TIME_H || defined __need_clock_t) 53 # define __clock_t_defined 1 54 55 # include <bits/types.h> 56 57 __BEGIN_NAMESPACE_STD 58 /* Returned by `clock'. */ 59 typedef __clock_t clock_t; 60 __END_NAMESPACE_STD 61 #if defined __USE_XOPEN || defined __USE_POSIX || defined __USE_MISC 62 __USING_NAMESPACE_STD(clock_t) 63 #endif 64 65 #endif /* clock_t not defined and <time.h> or need clock_t. */ 66 #undef __need_clock_t 67 68 #if !defined __time_t_defined && (defined _TIME_H || defined __need_time_t) 69 # define __time_t_defined 1 70 71 # include <bits/types.h> 72 73 __BEGIN_NAMESPACE_STD 74 /* Returned by `time'. */ 75 typedef __time_t time_t; 76 __END_NAMESPACE_STD 77 #if defined __USE_POSIX || defined __USE_MISC || defined __USE_SVID 78 __USING_NAMESPACE_STD(time_t) 79 #endif 80 81 #endif /* time_t not defined and <time.h> or need time_t. */ 82 #undef __need_time_t 83 84 #if !defined __clockid_t_defined && \ 85 ((defined _TIME_H && defined __USE_POSIX199309) || defined __need_clockid_t) 86 # define __clockid_t_defined 1 87 88 # include <bits/types.h> 89 90 /* Clock ID used in clock and timer functions. */ 91 typedef __clockid_t clockid_t; 92 93 #endif /* clockid_t not defined and <time.h> or need clockid_t. */ 94 #undef __clockid_time_t 95 96 #if !defined __timer_t_defined && \ 97 ((defined _TIME_H && defined __USE_POSIX199309) || defined __need_timer_t) 98 # define __timer_t_defined 1 99 100 # include <bits/types.h> 101 102 /* Timer ID returned by `timer_create'. */ 103 typedef __timer_t timer_t; 104 105 #endif /* timer_t not defined and <time.h> or need timer_t. */ 106 #undef __need_timer_t 107 108 109 #if !defined __timespec_defined && \ 110 ((defined _TIME_H && \ 111 (defined __USE_POSIX199309 || defined __USE_MISC)) || \ 112 defined __need_timespec) 113 # define __timespec_defined 1 114 115 # include <bits/types.h> /* This defines __time_t for us. */ 116 117 /* POSIX.1b structure for a time value. This is like a `struct timeval' but 118 has nanoseconds instead of microseconds. */ 119 struct timespec 120 { 121 __time_t tv_sec; /* Seconds. */ 122 long int tv_nsec; /* Nanoseconds. */ 123 }; 124 125 #endif /* timespec not defined and <time.h> or need timespec. */ 126 #undef __need_timespec 127 128 129 #ifdef _TIME_H 130 __BEGIN_NAMESPACE_STD 131 /* Used by other time functions. */ 132 struct tm 133 { 134 int tm_sec; /* Seconds. [0-60] (1 leap second) */ 135 int tm_min; /* Minutes. [0-59] */ 136 int tm_hour; /* Hours. [0-23] */ 137 int tm_mday; /* Day. [1-31] */ 138 int tm_mon; /* Month. [0-11] */ 139 int tm_year; /* Year - 1900. */ 140 int tm_wday; /* Day of week. [0-6] */ 141 int tm_yday; /* Days in year.[0-365] */ 142 int tm_isdst; /* DST. [-1/0/1]*/ 143 144 #ifdef __UCLIBC_HAS_TM_EXTENSIONS__ 145 #ifdef __USE_BSD 146 long int tm_gmtoff; /* Seconds east of UTC. */ 147 const char *tm_zone; /* Timezone abbreviation. */ 148 #else 149 long int __tm_gmtoff; /* Seconds east of UTC. */ 150 const char *__tm_zone; /* Timezone abbreviation. */ 151 #endif 152 #endif /* __UCLIBC_HAS_TM_EXTENSIONS__ */ 153 }; 154 __END_NAMESPACE_STD 155 #if defined __USE_XOPEN || defined __USE_POSIX || defined __USE_MISC 156 __USING_NAMESPACE_STD(tm) 157 #endif 158 159 160 #ifdef __USE_POSIX199309 161 /* POSIX.1b structure for timer start values and intervals. */ 162 struct itimerspec 163 { 164 struct timespec it_interval; 165 struct timespec it_value; 166 }; 167 168 /* We can use a simple forward declaration. */ 169 struct sigevent; 170 171 #endif /* POSIX.1b */ 172 173 #ifdef __USE_XOPEN2K 174 # ifndef __pid_t_defined 175 typedef __pid_t pid_t; 176 # define __pid_t_defined 177 # endif 178 #endif 179 180 181 __BEGIN_NAMESPACE_STD 182 /* Time used by the program so far (user time + system time). 183 The result / CLOCKS_PER_SECOND is program time in seconds. */ 184 extern clock_t clock (void) __THROW; 185 186 /* Return the current time and put it in *TIMER if TIMER is not NULL. */ 187 extern time_t time (time_t *__timer) __THROW; 188 libc_hidden_proto(time) 189 190 #ifdef __UCLIBC_HAS_FLOATS__ 191 /* Return the difference between TIME1 and TIME0. */ 192 extern double difftime (time_t __time1, time_t __time0) 193 __THROW __attribute__ ((__const__)); 194 #endif /* __UCLIBC_HAS_FLOATS__ */ 195 196 #ifdef _LIBC 197 # define CLOCK_IDFIELD_SIZE 3 198 #endif 199 200 /* Return the `time_t' representation of TP and normalize TP. */ 201 extern time_t mktime (struct tm *__tp) __THROW; 202 203 204 /* Format TP into S according to FORMAT. 205 Write no more than MAXSIZE characters and return the number 206 of characters written, or 0 if it would exceed MAXSIZE. */ 207 extern size_t strftime (char *__restrict __s, size_t __maxsize, 208 const char *__restrict __format, 209 const struct tm *__restrict __tp) __THROW; 210 __END_NAMESPACE_STD 211 212 # ifdef __USE_XOPEN 213 /* Parse S according to FORMAT and store binary time information in TP. 214 The return value is a pointer to the first unparsed character in S. */ 215 extern char *strptime (const char *__restrict __s, 216 const char *__restrict __fmt, struct tm *__tp) 217 __THROW; 218 # endif 219 220 #ifdef __UCLIBC_HAS_XLOCALE__ 221 # ifdef __USE_XOPEN2K8 222 /* Similar to the two functions above but take the information from 223 the provided locale and not the global locale. */ 224 # include <xlocale.h> 225 226 extern size_t strftime_l (char *__restrict __s, size_t __maxsize, 227 const char *__restrict __format, 228 const struct tm *__restrict __tp, 229 __locale_t __loc) __THROW; 230 libc_hidden_proto(strftime_l) 231 # endif 232 233 # ifdef __USE_GNU 234 extern char *strptime_l (const char *__restrict __s, 235 const char *__restrict __fmt, struct tm *__tp, 236 __locale_t __loc) __THROW; 237 libc_hidden_proto(strptime_l) 238 # endif 239 #endif 240 241 242 __BEGIN_NAMESPACE_STD 243 /* Return the `struct tm' representation of *TIMER 244 in Universal Coordinated Time (aka Greenwich Mean Time). */ 245 extern struct tm *gmtime (const time_t *__timer) __THROW; 246 247 /* Return the `struct tm' representation 248 of *TIMER in the local timezone. */ 249 extern struct tm *localtime (const time_t *__timer) __THROW; 250 libc_hidden_proto(localtime) 251 __END_NAMESPACE_STD 252 253 # if defined __USE_POSIX || defined __USE_MISC 254 /* Return the `struct tm' representation of *TIMER in UTC, 255 using *TP to store the result. */ 256 extern struct tm *gmtime_r (const time_t *__restrict __timer, 257 struct tm *__restrict __tp) __THROW; 258 259 /* Return the `struct tm' representation of *TIMER in local time, 260 using *TP to store the result. */ 261 extern struct tm *localtime_r (const time_t *__restrict __timer, 262 struct tm *__restrict __tp) __THROW; 263 libc_hidden_proto(localtime_r) 264 # endif /* POSIX or misc */ 265 266 __BEGIN_NAMESPACE_STD 267 /* Return a string of the form "Day Mon dd hh:mm:ss yyyy\n" 268 that is the representation of TP in this format. */ 269 extern char *asctime (const struct tm *__tp) __THROW; 270 libc_hidden_proto(asctime) 271 272 /* Equivalent to `asctime (localtime (timer))'. */ 273 extern char *ctime (const time_t *__timer) __THROW; 274 libc_hidden_proto(ctime) 275 __END_NAMESPACE_STD 276 277 # if defined __USE_POSIX || defined __USE_MISC 278 /* Reentrant versions of the above functions. */ 279 280 /* Return in BUF a string of the form "Day Mon dd hh:mm:ss yyyy\n" 281 that is the representation of TP in this format. */ 282 extern char *asctime_r (const struct tm *__restrict __tp, 283 char *__restrict __buf) __THROW; 284 libc_hidden_proto(asctime_r) 285 286 /* Equivalent to `asctime_r (localtime_r (timer, *TMP*), buf)'. */ 287 extern char *ctime_r (const time_t *__restrict __timer, 288 char *__restrict __buf) __THROW; 289 # endif /* POSIX or misc */ 290 291 # ifdef __USE_POSIX 292 /* Same as above. */ 293 extern char *tzname[2]; 294 295 /* Set time conversion information from the TZ environment variable. 296 If TZ is not defined, a locale-dependent default is used. */ 297 extern void tzset (void) __THROW; 298 libc_hidden_proto(tzset) 299 # endif 300 301 # if defined __USE_SVID || defined __USE_XOPEN 302 extern int daylight; 303 extern long int timezone; 304 # endif 305 306 # ifdef __USE_SVID 307 /* Set the system time to *WHEN. 308 This call is restricted to the superuser. */ 309 extern int stime (const time_t *__when) __THROW; 310 libc_hidden_proto(stime) 311 # endif 312 313 314 /* Nonzero if YEAR is a leap year (every 4 years, 315 except every 100th isn't, and every 400th is). */ 316 # define __isleap(year) \ 317 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) 318 319 320 # ifdef __USE_MISC 321 /* Miscellaneous functions many Unices inherited from the public domain 322 localtime package. These are included only for compatibility. */ 323 324 /* Like `mktime', but for TP represents Universal Time, not local time. */ 325 extern time_t timegm (struct tm *__tp) __THROW; 326 327 /* Another name for `mktime'. */ 328 extern time_t timelocal (struct tm *__tp) __THROW; 329 330 /* Return the number of days in YEAR. */ 331 extern int dysize (int __year) __THROW __attribute__ ((__const__)); 332 # endif 333 334 335 # ifdef __USE_POSIX199309 336 # if defined __UCLIBC_HAS_REALTIME__ 337 /* Pause execution for a number of nanoseconds. 338 339 This function is a cancellation point and therefore not marked with 340 __THROW. */ 341 extern int nanosleep (const struct timespec *__requested_time, 342 struct timespec *__remaining); 343 libc_hidden_proto(nanosleep) 344 345 346 /* Get resolution of clock CLOCK_ID. */ 347 extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW; 348 libc_hidden_proto(clock_getres) 349 350 /* Get current value of clock CLOCK_ID and store it in TP. */ 351 extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW; 352 353 /* Set clock CLOCK_ID to value TP. */ 354 extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp) 355 __THROW; 356 # endif /* __UCLIBC_HAS_REALTIME__ */ 357 358 # if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__ 359 /* High-resolution sleep with the specified clock. 360 361 This function is a cancellation point and therefore not marked with 362 __THROW. */ 363 extern int clock_nanosleep (clockid_t __clock_id, int __flags, 364 const struct timespec *__req, 365 struct timespec *__rem); 366 367 /* Return clock ID for CPU-time clock. */ 368 extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) __THROW; 369 # endif 370 371 # if defined __UCLIBC_HAS_REALTIME__ 372 /* Create new per-process timer using CLOCK_ID. */ 373 extern int timer_create (clockid_t __clock_id, 374 struct sigevent *__restrict __evp, 375 timer_t *__restrict __timerid) __THROW; 376 377 /* Delete timer TIMERID. */ 378 extern int timer_delete (timer_t __timerid) __THROW; 379 380 /* Set timer TIMERID to VALUE, returning old value in OVLAUE. */ 381 extern int timer_settime (timer_t __timerid, int __flags, 382 const struct itimerspec *__restrict __value, 383 struct itimerspec *__restrict __ovalue) __THROW; 384 385 /* Get current value of timer TIMERID and store it in VLAUE. */ 386 extern int timer_gettime (timer_t __timerid, struct itimerspec *__value) 387 __THROW; 388 389 /* Get expiration overrun for timer TIMERID. */ 390 extern int timer_getoverrun (timer_t __timerid) __THROW; 391 # endif /* __UCLIBC_HAS_REALTIME__ */ 392 # endif /* __USE_POSIX199309 */ 393 394 __END_DECLS 395 396 #endif /* <time.h> included. */ 397 398 #endif /* <time.h> not already included. */ 399