time.h 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU Lesser General Public
  4. License version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details.
  6. Module Name:
  7. time.h
  8. Abstract:
  9. This header contains time related definitions.
  10. Author:
  11. Evan Green 22-Jul-2013
  12. --*/
  13. #ifndef _TIME_H
  14. #define _TIME_H
  15. //
  16. // ------------------------------------------------------------------- Includes
  17. //
  18. #include <libcbase.h>
  19. #include <signal.h>
  20. #include <stddef.h>
  21. //
  22. // ---------------------------------------------------------------- Definitions
  23. //
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. //
  28. // Define the types of clocks that can be accessed.
  29. //
  30. //
  31. // Wall clock time
  32. //
  33. #define CLOCK_REALTIME 0
  34. //
  35. // High resolution hardware timer
  36. //
  37. #define CLOCK_MONOTONIC 1
  38. //
  39. // CPU time for the process
  40. //
  41. #define CLOCK_PROCESS_CPUTIME_ID 2
  42. //
  43. // CPU time for the thread
  44. //
  45. #define CLOCK_THREAD_CPUTIME_ID 3
  46. //
  47. // Monotonic clock, unscaled
  48. //
  49. #define CLOCK_MONOTONIC_RAW 4
  50. //
  51. // Recent realtime clock value, updated regularly.
  52. //
  53. #define CLOCK_REALTIME_COARSE 5
  54. //
  55. // Recent monotonic clock value, updated regularly.
  56. //
  57. #define CLOCK_MONOTONIC_COARSE 6
  58. //
  59. // Monotonic clock value plus time spent in suspension.
  60. //
  61. #define CLOCK_BOOTTIME 7
  62. //
  63. // Define the flags that can be passed to the set timer function.
  64. //
  65. //
  66. // Set this flag to indicate that the value to be set is an absolute time.
  67. //
  68. #define TIMER_ABSTIME 0x00000001
  69. //
  70. // Define the value to convert the units returned in the clock function to
  71. // seconds.
  72. //
  73. #define CLOCKS_PER_SEC 1000000
  74. //
  75. // ------------------------------------------------------ Data Type Definitions
  76. //
  77. /*++
  78. Structure Description:
  79. This structure stores information about an interval timer.
  80. Members:
  81. it_interval - Stores the period of the timer for periodic timers, or 0.0 if
  82. the timer is a one-shot timer.
  83. it_value - Stores the due time of the timer.
  84. --*/
  85. struct itimerspec {
  86. struct timespec it_interval;
  87. struct timespec it_value;
  88. };
  89. /*++
  90. Structure Description:
  91. This structure describes the C library concept of calendar time.
  92. Members:
  93. tm_sec - Stores the second. Valid values are between 0 and 60 (for leap
  94. seconds).
  95. tm_min - Stores the minute. Valid values are between 0 and 59.
  96. tm_hour - Stores the hour. Valid values are between 0 and 23.
  97. tm_mday - Stores the day of the month. Valid values are between 1 and 31.
  98. tm_mon - Stores the month. Valid values are between 0 and 11.
  99. tm_year - Stores the number of years since 1900. Valid values are between
  100. -1899 and 8099 (for actual calendar years between 1 and 9999).
  101. tm_wday - Stores the day of the week. Valid values are between 0 and 6,
  102. with 0 being Sunday and 6 being Saturday.
  103. tm_yday - Stores the day of the year. Valid values are between 0 and 365.
  104. tm_isdst - Stores a value indicating if the given time is represented in
  105. daylight saving time. Usually 0 indicates standard time, 1 indicates
  106. daylight saving time, and -1 indicates "unknown".
  107. tm_nanosecond - Stores the nanosecond. Valid values are between 0 and
  108. 999,999,999.
  109. tm_gmtoff - Stores the offset from Greenwich Mean Time in seconds that
  110. this time is interpreted in.
  111. tm_zone - Stores a pointer to a constant string containing the time zone
  112. name. The user should not modify or free this buffer.
  113. --*/
  114. struct tm {
  115. int tm_sec;
  116. int tm_min;
  117. int tm_hour;
  118. int tm_mday;
  119. int tm_mon;
  120. int tm_year;
  121. int tm_wday;
  122. int tm_yday;
  123. int tm_isdst;
  124. int tm_nanosecond;
  125. int tm_gmtoff;
  126. const char *tm_zone;
  127. };
  128. //
  129. // -------------------------------------------------------------------- Globals
  130. //
  131. //
  132. // This variable is set to zero if Daylight Saving time should never be applied
  133. // for the timezone in use, or non-zero otherwise.
  134. //
  135. LIBC_API extern int daylight;
  136. //
  137. // This variable is set to the difference in seconds between Universal
  138. // Coordinated Time (UTC) and local standard time.
  139. //
  140. LIBC_API extern long timezone;
  141. //
  142. // This variable is set to contain two pointers to strings. The first one
  143. // points to the name of the timezone in standard time, and the second one
  144. // pointers to the name of the timezone in Daylight Saving time.
  145. //
  146. LIBC_API extern char *tzname[2];
  147. //
  148. // -------------------------------------------------------- Function Prototypes
  149. //
  150. LIBC_API
  151. clock_t
  152. clock (
  153. void
  154. );
  155. /*++
  156. Routine Description:
  157. This routine returns the best approximation of the processor time used
  158. by the process since the process invocation.
  159. Arguments:
  160. None.
  161. Return Value:
  162. Returns the clock time used by the current process, which can be divided
  163. by CLOCKS_PER_SEC to get the number of seconds of processor time used by
  164. the process.
  165. -1 if the processor time is not available or cannot be represented.
  166. --*/
  167. LIBC_API
  168. int
  169. clock_getcpuclockid (
  170. pid_t ProcessId,
  171. clockid_t *ClockId
  172. );
  173. /*++
  174. Routine Description:
  175. This routine gets the clock ID for the CPU time clock of the given
  176. process.
  177. Arguments:
  178. ProcessId - Supplies the ID of the process whose CPU time clock ID is being
  179. queried.
  180. ClockId - Supplies a pointer that receives the CPU time clock ID for the
  181. given process.
  182. Return Value:
  183. 0 on success. The returned clock ID will be in the clock ID parameter.
  184. -1 on failure, and errno will be set to contain more information.
  185. --*/
  186. LIBC_API
  187. int
  188. clock_getres (
  189. clockid_t ClockId,
  190. struct timespec *Resolution
  191. );
  192. /*++
  193. Routine Description:
  194. This routine gets the resolution for the given clock. Time values for calls
  195. to get or set this clock will be limited by the precision of the resolution.
  196. Arguments:
  197. ClockId - Supplies the ID of the clock whose resolution is to be queried.
  198. Resolution - Supplies a pointer that receives the resolution of the given
  199. clock.
  200. Return Value:
  201. 0 on success. The returned resolution will be in the resolution parameter.
  202. -1 on failure, and errno will be set to contain more information.
  203. --*/
  204. LIBC_API
  205. int
  206. clock_gettime (
  207. clockid_t ClockId,
  208. struct timespec *Time
  209. );
  210. /*++
  211. Routine Description:
  212. This routine gets the current time for the given clock.
  213. Arguments:
  214. ClockId - Supplies the ID of the clock whose time is being queried.
  215. Time - Supplies a pointer that receives the current value of the queried
  216. clock.
  217. Return Value:
  218. 0 on success. The returned time will be in the time parameter.
  219. -1 on failure, and errno will be set to contain more information.
  220. --*/
  221. LIBC_API
  222. int
  223. clock_settime (
  224. clockid_t ClockId,
  225. const struct timespec *NewTime
  226. );
  227. /*++
  228. Routine Description:
  229. This routine sets the time for the given clock.
  230. Arguments:
  231. ClockId - Supplies the ID of the clock whose time is to be set.
  232. NewTime - Supplies a pointer to the new time to set for the given clock.
  233. Return Value:
  234. 0 on success.
  235. -1 on failure, and errno will be set to contain more information.
  236. --*/
  237. LIBC_API
  238. int
  239. clock_nanosleep (
  240. clockid_t ClockId,
  241. int Flags,
  242. const struct timespec *RequestedTime,
  243. struct timespec *RemainingTime
  244. );
  245. /*++
  246. Routine Description:
  247. This routine suspends execution of the calling thread until either the
  248. given clock interval has expired or a signal is delivered. If absolute time
  249. is specified, then the thread will be suspended until the absolute time is
  250. reached or a signal is delivered.
  251. Arguments:
  252. ClockId - Supplies the ID of the clock to use to measure the requested time.
  253. Flags - Supplies a bitmask of flags. See TIMER_*.
  254. RequestedTime - Supplies a pointer to the requested time interval to wait
  255. or the absolute time until which to wait.
  256. RemainingTime - Supplies an optional pointer that receives the remaining
  257. time if the thread is interrupted by a signal.
  258. Return Value:
  259. 0 on success or standard error value on failure or interruption.
  260. --*/
  261. LIBC_API
  262. char *
  263. asctime (
  264. const struct tm *Time
  265. );
  266. /*++
  267. Routine Description:
  268. This routine converts the given time structure into a string. This routine
  269. is neither reentrant nor thread safe, and the results returned may be
  270. overwritten by subsequent calls to ctime, gmtime, and localtime. It is
  271. recommended that new applications use asctime_r. The format of the result
  272. takes the following form (as an example): "Tue Jan 28 11:38:09 1986".
  273. Arguments:
  274. Time - Supplies a pointer to the time structure to convert.
  275. Return Value:
  276. Returns a pointer to the buffer on success.
  277. NULL on failure.
  278. --*/
  279. LIBC_API
  280. char *
  281. asctime_r (
  282. const struct tm *Time,
  283. char *Buffer
  284. );
  285. /*++
  286. Routine Description:
  287. This routine converts the given time structure into a string. This routine
  288. is reentrant and thread safe, as it uses only the passed in buffers. The
  289. format of the result takes the following form (as an example):
  290. "Tue Jan 28 11:38:09 1986".
  291. Arguments:
  292. Time - Supplies a pointer to the time structure to convert.
  293. Buffer - Supplies a pointer to a buffer that must be at least 26 bytes in
  294. size.
  295. Return Value:
  296. Returns a pointer to the buffer on success.
  297. NULL on failure.
  298. --*/
  299. LIBC_API
  300. char *
  301. ctime (
  302. const time_t *TimeValue
  303. );
  304. /*++
  305. Routine Description:
  306. This routine converts the given time structure into a string. This routine
  307. is neither reentrant nor thread safe, and the results returned may be
  308. overwritten by subsequent calls to ctime, gmtime, and localtime. It is
  309. recommended that new applications use ctime_r. This routine is equivalent
  310. to calling asctime(localtime(Time)).
  311. Arguments:
  312. TimeValue - Supplies the time value to convert.
  313. Return Value:
  314. Returns a pointer to the buffer on success.
  315. NULL on failure.
  316. --*/
  317. LIBC_API
  318. char *
  319. ctime_r (
  320. const time_t *TimeValue,
  321. char *Buffer
  322. );
  323. /*++
  324. Routine Description:
  325. This routine converts the given time structure into a string. This routine
  326. is reentrant and thread safe, as it uses only the passed in buffers. This
  327. routine is equivalent to calling asctime(localtime(Time)).
  328. Arguments:
  329. TimeValue - Supplies the time value to convert.
  330. Buffer - Supplies a pointer to a buffer that must be at least 26 bytes in
  331. size.
  332. Return Value:
  333. Returns a pointer to the buffer on success.
  334. NULL on failure.
  335. --*/
  336. LIBC_API
  337. double
  338. difftime (
  339. time_t LeftTimeValue,
  340. time_t RightTimeValue
  341. );
  342. /*++
  343. Routine Description:
  344. This routine computes the difference between two time values:
  345. LeftTimeValue - RightTimeValue.
  346. Arguments:
  347. LeftTimeValue - Supplies the first time value, the value to subtract from.
  348. RightTimeValue - Supplies the second time value, the value to subtract.
  349. Return Value:
  350. Returns the number of seconds between the two times as a double.
  351. --*/
  352. LIBC_API
  353. struct tm *
  354. gmtime (
  355. const time_t *TimeValue
  356. );
  357. /*++
  358. Routine Description:
  359. This routine converts the given time value into a broken down calendar time
  360. in the GMT time zone. This routine is neither reentrant nor thread safe.
  361. Arguments:
  362. TimeValue - Supplies a pointer to the time value to convert.
  363. Return Value:
  364. Returns a pointer to a broken down time structure on success. This buffer
  365. may be overwritten by subsequent calls to gmtime or localtime.
  366. --*/
  367. LIBC_API
  368. struct tm *
  369. gmtime_r (
  370. const time_t *TimeValue,
  371. struct tm *Result
  372. );
  373. /*++
  374. Routine Description:
  375. This routine converts the given time value into a broken down calendar time
  376. in the GMT time zone. This routine is reentrant and thread safe.
  377. Arguments:
  378. TimeValue - Supplies a pointer to the time value to convert.
  379. Result - Supplies a pointer where the result will be returned.
  380. Return Value:
  381. Returns the result parameter on success.
  382. NULL on failure.
  383. --*/
  384. LIBC_API
  385. struct tm *
  386. localtime (
  387. const time_t *TimeValue
  388. );
  389. /*++
  390. Routine Description:
  391. This routine converts the given time value into a broken down calendar time
  392. in the current local time zone. This routine is neither reentrant nor
  393. thread safe.
  394. Arguments:
  395. TimeValue - Supplies a pointer to the time value to convert.
  396. Return Value:
  397. Returns a pointer to a broken down time structure on success. This buffer
  398. may be overwritten by subsequent calls to gmtime or localtime.
  399. --*/
  400. LIBC_API
  401. struct tm *
  402. localtime_r (
  403. const time_t *TimeValue,
  404. struct tm *Result
  405. );
  406. /*++
  407. Routine Description:
  408. This routine converts the given time value into a broken down calendar time
  409. in the current local time zone. This routine is reentrant and thread safe.
  410. Arguments:
  411. TimeValue - Supplies a pointer to the time value to convert.
  412. Result - Supplies a pointer where the result will be returned.
  413. Return Value:
  414. Returns the result parameter on success.
  415. NULL on failure.
  416. --*/
  417. LIBC_API
  418. time_t
  419. timegm (
  420. struct tm *Time
  421. );
  422. /*++
  423. Routine Description:
  424. This routine converts a broken down time structure, given in GMT time, back
  425. into its corresponding time value, in seconds since the Epoch, midnight on
  426. January 1, 1970 GMT. It will also normalize the given time structure so
  427. that each member is in the correct range.
  428. Arguments:
  429. Time - Supplies a pointer to the broken down time structure.
  430. Return Value:
  431. Returns the time value corresponding to the given broken down time.
  432. -1 on failure, and errno will be set to contain more information. Note that
  433. -1 can also be returned as a valid offset from the Epoch.
  434. --*/
  435. LIBC_API
  436. time_t
  437. mktime (
  438. struct tm *Time
  439. );
  440. /*++
  441. Routine Description:
  442. This routine converts a broken down time structure, given in local time,
  443. back into its corresponding time value, in seconds since the Epoch,
  444. midnight on January 1, 1970 GMT. It will also normalize the given time
  445. structure so that each member is in the correct range.
  446. Arguments:
  447. Time - Supplies a pointer to the broken down time structure.
  448. Return Value:
  449. Returns the time value corresponding to the given broken down time.
  450. -1 on failure, and errno will be set to contain more information. Note that
  451. -1 can also be returned as a valid offset from the Epoch.
  452. --*/
  453. LIBC_API
  454. size_t
  455. strftime (
  456. char *Buffer,
  457. size_t BufferSize,
  458. const char *Format,
  459. const struct tm *Time
  460. );
  461. /*++
  462. Routine Description:
  463. This routine converts the given calendar time into a string governed by
  464. the given format string.
  465. Arguments:
  466. Buffer - Supplies a pointer where the converted string will be returned.
  467. BufferSize - Supplies the size of the string buffer in bytes.
  468. Format - Supplies the format string to govern the conversion. Ordinary
  469. characters in the format string will be copied verbatim to the output
  470. string. Conversions will be substituted for their corresponding value
  471. in the provided calendar time. Conversions start with a '%' character,
  472. followed by an optional E or O character, followed by a conversion
  473. specifier. The conversion specifier can take the following values:
  474. %a - Replaced by the abbreviated weekday.
  475. %A - Replaced by the full weekday.
  476. %b - Replaced by the abbreviated month name.
  477. %B - Replaced by the full month name.
  478. %c - Replaced by the locale's appropriate date and time representation.
  479. %C - Replaced by the year divided by 100 (century) [00,99].
  480. %d - Replaced by the day of the month [01,31].
  481. %D - Equivalent to "%m/%d/%y".
  482. %e - Replaced by the day of the month [ 1,31]. A single digit is
  483. preceded by a space.
  484. %F - Equivalent to "%Y-%m-%d" (the ISO 8601:2001 date format).
  485. %G - The ISO 8601 week-based year [0001,9999]. The week-based year and
  486. the Gregorian year can differ in the first week of January.
  487. %h - Equivalent to %b (abbreviated month).
  488. %H - Replaced by the 24 hour clock hour [00,23].
  489. %I - Replaced by the 12 hour clock hour [01,12].
  490. %J - Replaced by the nanosecond [0,999999999].
  491. %j - Replaced by the day of the year [001,366].
  492. %m - Replaced by the month number [01,12].
  493. %M - Replaced by the minute [00,59].
  494. %N - Replaced by the microsecond [0,999999]
  495. %n - Replaced by a newline.
  496. %p - Replaced by "AM" or "PM".
  497. %P - Replaced by "am" or "pm".
  498. %q - Replaced by the millisecond [0,999].
  499. %r - Replaced by the time in AM/PM notation: "%I:%M:%S %p".
  500. %R - Replaced by the time in 24 hour notation: "%H:%M".
  501. %S - Replaced by the second [00,60].
  502. %s - Replaced by the number of seconds since 1970 GMT.
  503. %t - Replaced by a tab.
  504. %T - Replaced by the time: "%H:%M:%S".
  505. %u - Replaced by the weekday number, with 1 representing Monday [1,7].
  506. %U - Replaced by the week number of the year [00,53]. The first Sunday
  507. of January is the first day of week 1. Days before this are week 0.
  508. %V - Replaced by the week number of the year with Monday as the first
  509. day in the week [01,53]. If the week containing January 1st has 4
  510. or more days in the new year, it is considered week 1. Otherwise,
  511. it is the last week of the previous year, and the next week is 1.
  512. %w - Replaced by the weekday number [0,6], with 0 representing Sunday.
  513. %W - Replaced by the week number [00,53]. The first Monday of January
  514. is the first day of week 1. Days before this are in week 0.
  515. %x - Replaced by the locale's appropriate date representation.
  516. %X - Replaced by the locale's appropriate time representation.
  517. %y - Replaced by the last two digits of the year [00,99].
  518. %Y - Replaced by the full four digit year [0001,9999].
  519. %z - Replaced by the offset from UTC in the standard ISO 8601:2000
  520. standard format (+hhmm or -hhmm), or by no characters if no
  521. timezone is terminable. If the "is daylight saving" member of the
  522. calendar structure is greater than zero, then the daylight saving
  523. offset is used. If the dayslight saving member of the calendar
  524. structure is negative, no characters are returned.
  525. %Z - Replaced by the timezone name or abbreviation, or by no bytes if
  526. no timezone information exists.
  527. %% - Replaced by a literal '%'.
  528. Time - Supplies a pointer to the calendar time value to use in the
  529. substitution.
  530. Return Value:
  531. Returns the number of characters written to the output buffer, not
  532. including the null terminator.
  533. --*/
  534. LIBC_API
  535. char *
  536. strptime (
  537. const char *Buffer,
  538. const char *Format,
  539. struct tm *Time
  540. );
  541. /*++
  542. Routine Description:
  543. This routine scans the given input string into values in the calendar time,
  544. using the specified format.
  545. Arguments:
  546. Buffer - Supplies a pointer to the null terminated string to scan.
  547. Format - Supplies the format string to govern the conversion. Ordinary
  548. characters in the format string will be scanned verbatim from the input.
  549. Whitespace characters in the format will cause all whitespace at the
  550. current position in the input to be scanned. Conversions will be
  551. scanned for their corresponding value in the provided calendar time.
  552. Conversions start with a '%' character, followed by an optional E or O
  553. character, followed by a conversion specifier. The conversion specifier
  554. can take the following values:
  555. %a - The day of the weekday name, either the full or abbreviated name.
  556. %A - Equivalent to %a.
  557. %b - The month name, either the full or abbreviated name.
  558. %B - Equivalent to %b.
  559. %c - Replaced by the locale's appropriate date and time representation.
  560. %C - The year divided by 100 (century) [00,99].
  561. %d - The day of the month [01,31].
  562. %D - Equivalent to "%m/%d/%y".
  563. %e - Equivalent to %d.
  564. %h - Equivalent to %b (month name).
  565. %H - The 24 hour clock hour [00,23].
  566. %I - The 12 hour clock hour [01,12].
  567. %J - Replaced by the nanosecond [0,999999999].
  568. %j - The day of the year [001,366].
  569. %m - The month number [01,12].
  570. %M - The minute [00,59].
  571. %N - The microsecond [0,999999]
  572. %n - Any whitespace.
  573. %p - The equivalent of "AM" or "PM".
  574. %q - The millisecond [0,999].
  575. %r - Replaced by the time in AM/PM notation: "%I:%M:%S %p".
  576. %R - Replaced by the time in 24 hour notation: "%H:%M".
  577. %S - The second [00,60].
  578. %t - Any white space.
  579. %T - Replaced by the time: "%H:%M:%S".
  580. %u - Replaced by the weekday number, with 1 representing Monday [1,7].
  581. %U - The week number of the year [00,53]. The first Sunday of January is
  582. the first day of week 1. Days before this are week 0.
  583. %w - The weekday number [0,6], with 0 representing Sunday.
  584. %W - The week number [00,53]. The first Monday of January is the first
  585. day of week 1. Days before this are in week 0.
  586. %x - Replaced by the locale's appropriate date representation.
  587. %X - Replaced by the locale's appropriate time representation.
  588. %y - The last two digits of the year [00,99].
  589. %Y - The full four digit year [0001,9999].
  590. %% - Replaced by a literal '%'.
  591. Time - Supplies a pointer to the calendar time value to place the
  592. values in. Only the values that are scanned in are modified.
  593. Return Value:
  594. Returns the a pointer to the input string after the last character scanned.
  595. NULL if the result coult not be scanned.
  596. --*/
  597. LIBC_API
  598. time_t
  599. time (
  600. time_t *Result
  601. );
  602. /*++
  603. Routine Description:
  604. This routine returns the current time in terms of seconds from the Epoch,
  605. midnight on January 1, 1970 GMT.
  606. Arguments:
  607. Result - Supplies an optional pointer where the current time will be
  608. returned. This will be the same as the return value.
  609. Return Value:
  610. Returns the current time since the epoch.
  611. --*/
  612. LIBC_API
  613. int
  614. timer_create (
  615. clockid_t ClockId,
  616. struct sigevent *Event,
  617. timer_t *TimerId
  618. );
  619. /*++
  620. Routine Description:
  621. This routine creates a new timer.
  622. Arguments:
  623. ClockId - Supplies the clock type ID. See CLOCK_* definitions. The most
  624. common value here is CLOCK_REALTIME.
  625. Event - Supplies a pointer to an event structure describing what should
  626. happen when the timer expires. If this parameter is NULL, then the
  627. timer will be treated as if this structure had specified that a
  628. SIGALRM signal should be generated with the timer ID number set as the
  629. signal value.
  630. TimerId - Supplies a pointer where the timer ID number will be returned on
  631. success.
  632. Return Value:
  633. 0 on success. The returned timer ID will be in the timer parameter.
  634. -1 on failure, and errno will be set to contain more information.
  635. --*/
  636. LIBC_API
  637. int
  638. timer_delete (
  639. timer_t TimerId
  640. );
  641. /*++
  642. Routine Description:
  643. This routine disarms and deletes the timer with the given ID.
  644. Arguments:
  645. TimerId - Supplies the ID of the timer to delete.
  646. Return Value:
  647. 0 on success.
  648. -1 on failure and errno will be set to EINVAL if the given timer handle is
  649. invalid.
  650. --*/
  651. LIBC_API
  652. int
  653. timer_gettime (
  654. timer_t TimerId,
  655. struct itimerspec *Value
  656. );
  657. /*++
  658. Routine Description:
  659. This routine gets the current timer information for the given timer.
  660. Arguments:
  661. TimerId - Supplies the ID of the timer to query.
  662. Value - Supplies a pointer where the remaining time on the timer will be
  663. returned.
  664. Return Value:
  665. 0 on success.
  666. -1 on failure and errno will be set to contain more information.
  667. --*/
  668. LIBC_API
  669. int
  670. timer_settime (
  671. timer_t TimerId,
  672. int Flags,
  673. const struct itimerspec *Value,
  674. struct itimerspec *OldValue
  675. );
  676. /*++
  677. Routine Description:
  678. This routine sets the current timer information for the given timer.
  679. Arguments:
  680. TimerId - Supplies the ID of the timer to set.
  681. Flags - Supplies a bitfield of flags. See TIMER_ABSTIME and friends.
  682. Value - Supplies a pointer where the remaining time on the timer will be
  683. returned.
  684. OldValue - Supplies an optional pointer where the structure containing the
  685. remaining time on the timer before this call will be returned.
  686. Return Value:
  687. 0 on success.
  688. -1 on failure and errno will be set to contain more information.
  689. --*/
  690. LIBC_API
  691. int
  692. timer_getoverrun (
  693. timer_t TimerId
  694. );
  695. /*++
  696. Routine Description:
  697. This routine returns the overrun count for the given timer. The overrun
  698. count can be queried during a signal, and represents the number of
  699. additional timer expiries that occurred before the signal was accepted by
  700. the process. If added to the count of signals that have occurred it
  701. represents the total number of expiries of the given periodic timer.
  702. Arguments:
  703. TimerId - Supplies the timer to query.
  704. Return Value:
  705. Returns the overrun count on success.
  706. -1 on failure, and errno will be set to contain more information.
  707. --*/
  708. LIBC_API
  709. void
  710. tzset (
  711. void
  712. );
  713. /*++
  714. Routine Description:
  715. This routine uses the values of the TZ environment variable to set time
  716. conversion information used by ctime, localtime, mktime, and strftime. If
  717. TZ is absent from the environment, a default timezone will be used.
  718. Arguments:
  719. None.
  720. Return Value:
  721. None.
  722. --*/
  723. LIBC_API
  724. int
  725. nanosleep (
  726. const struct timespec *RequestedTime,
  727. struct timespec *RemainingTime
  728. );
  729. /*++
  730. Routine Description:
  731. This routine suspends execution of the calling thread until either the
  732. given requested time elapses or a signal was delivered. If a signal was
  733. delivered, then the time remaining in the interval is reported.
  734. Arguments:
  735. RequestedTime - Supplies a pointer to the requested interval wait time.
  736. RemainingTime - Supplies an optional pointer that receives the time
  737. remaining in the interval if the routine is interrupted by a signal.
  738. Return Value:
  739. 0 on success.
  740. -1 on failure, and errno will be set to contain more information.
  741. --*/
  742. #ifdef __cplusplus
  743. }
  744. #endif
  745. #endif