Subversion Repositories Kolibri OS

Rev

Rev 4874 | Rev 6099 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.  * time.h
  3.  *
  4.  * Struct and function declarations for dealing with time.
  5.  */
  6.  
  7. #ifndef _TIME_H_
  8. #define _TIME_H_
  9.  
  10. #include "_ansi.h"
  11. #include <sys/reent.h>
  12.  
  13. #define __need_size_t
  14. #define __need_NULL
  15. #include <stddef.h>
  16.  
  17. /* Get _CLOCKS_PER_SEC_ */
  18. #include <machine/time.h>
  19.  
  20. #ifndef _CLOCKS_PER_SEC_
  21. #define _CLOCKS_PER_SEC_ 1000
  22. #endif
  23.  
  24. #define CLOCKS_PER_SEC _CLOCKS_PER_SEC_
  25. #define CLK_TCK CLOCKS_PER_SEC
  26.  
  27. #include <sys/types.h>
  28.  
  29. _BEGIN_STD_C
  30.  
  31. struct tm
  32. {
  33.   int   tm_sec;
  34.   int   tm_min;
  35.   int   tm_hour;
  36.   int   tm_mday;
  37.   int   tm_mon;
  38.   int   tm_year;
  39.   int   tm_wday;
  40.   int   tm_yday;
  41.   int   tm_isdst;
  42. };
  43.  
  44. clock_t    _EXFUN(clock,    (void));
  45. double     _EXFUN(difftime, (time_t _time2, time_t _time1));
  46. time_t     _EXFUN(mktime,   (struct tm *_timeptr));
  47. time_t     _EXFUN(time,     (time_t *_timer));
  48. #ifndef _REENT_ONLY
  49. char      *_EXFUN(asctime,  (const struct tm *_tblock));
  50. char      *_EXFUN(ctime,    (const time_t *_time));
  51. struct tm *_EXFUN(gmtime,   (const time_t *_timer));
  52. struct tm *_EXFUN(localtime,(const time_t *_timer));
  53. #endif
  54. size_t     _EXFUN(strftime, (char *__restrict _s,
  55.                              size_t _maxsize, const char *__restrict _fmt,
  56.                              const struct tm *__restrict _t));
  57.  
  58. char      *_EXFUN(asctime_r,    (const struct tm *__restrict,
  59.                                  char *__restrict));
  60. char      *_EXFUN(ctime_r,      (const time_t *, char *));
  61. struct tm *_EXFUN(gmtime_r,     (const time_t *__restrict,
  62.                                  struct tm *__restrict));
  63. struct tm *_EXFUN(localtime_r,  (const time_t *__restrict,
  64.                                  struct tm *__restrict));
  65.  
  66. _END_STD_C
  67.  
  68. #ifdef __cplusplus
  69. extern "C" {
  70. #endif
  71.  
  72. #ifndef __STRICT_ANSI__
  73. char      *_EXFUN(strptime,     (const char *__restrict,
  74.                                  const char *__restrict,
  75.                                  struct tm *__restrict));
  76. _VOID      _EXFUN(tzset,        (_VOID));
  77. _VOID      _EXFUN(_tzset_r,     (struct _reent *));
  78.  
  79. typedef struct __tzrule_struct
  80. {
  81.   char ch;
  82.   int m;
  83.   int n;
  84.   int d;
  85.   int s;
  86.   time_t change;
  87.   long offset; /* Match type of _timezone. */
  88. } __tzrule_type;
  89.  
  90. typedef struct __tzinfo_struct
  91. {
  92.   int __tznorth;
  93.   int __tzyear;
  94.   __tzrule_type __tzrule[2];
  95. } __tzinfo_type;
  96.  
  97. __tzinfo_type *_EXFUN (__gettzinfo, (_VOID));
  98.  
  99. /* getdate functions */
  100.  
  101. #ifdef HAVE_GETDATE
  102. #ifndef _REENT_ONLY
  103. #define getdate_err (*__getdate_err())
  104. int *_EXFUN(__getdate_err,(_VOID));
  105.  
  106. struct tm *     _EXFUN(getdate, (const char *));
  107. /* getdate_err is set to one of the following values to indicate the error.
  108.      1  the DATEMSK environment variable is null or undefined,
  109.      2  the template file cannot be opened for reading,
  110.      3  failed to get file status information,
  111.      4  the template file is not a regular file,
  112.      5  an error is encountered while reading the template file,
  113.      6  memory allication failed (not enough memory available),
  114.      7  there is no line in the template that matches the input,
  115.      8  invalid input specification  */
  116. #endif /* !_REENT_ONLY */
  117.  
  118. /* getdate_r returns the error code as above */
  119. int             _EXFUN(getdate_r, (const char *, struct tm *));
  120. #endif /* HAVE_GETDATE */
  121.  
  122. /* defines for the opengroup specifications Derived from Issue 1 of the SVID.  */
  123. extern __IMPORT long _timezone;
  124. extern __IMPORT int _daylight;
  125. extern __IMPORT char *_tzname[2];
  126.  
  127. /* POSIX defines the external tzname being defined in time.h */
  128. #ifndef tzname
  129. #define tzname _tzname
  130. #endif
  131. #endif /* !__STRICT_ANSI__ */
  132.  
  133. #ifdef __cplusplus
  134. }
  135. #endif
  136.  
  137. #include <sys/features.h>
  138.  
  139. #ifdef __CYGWIN__
  140. #include <cygwin/time.h>
  141. #endif /*__CYGWIN__*/
  142.  
  143. #if defined(_POSIX_TIMERS)
  144.  
  145. #include <signal.h>
  146.  
  147. #ifdef __cplusplus
  148. extern "C" {
  149. #endif
  150.  
  151. /* Clocks, P1003.1b-1993, p. 263 */
  152.  
  153. int _EXFUN(clock_settime, (clockid_t clock_id, const struct timespec *tp));
  154. int _EXFUN(clock_gettime, (clockid_t clock_id, struct timespec *tp));
  155. int _EXFUN(clock_getres,  (clockid_t clock_id, struct timespec *res));
  156.  
  157. /* Create a Per-Process Timer, P1003.1b-1993, p. 264 */
  158.  
  159. int _EXFUN(timer_create,
  160.         (clockid_t clock_id,
  161.         struct sigevent *__restrict evp,
  162.         timer_t *__restrict timerid));
  163.  
  164. /* Delete a Per_process Timer, P1003.1b-1993, p. 266 */
  165.  
  166. int _EXFUN(timer_delete, (timer_t timerid));
  167.  
  168. /* Per-Process Timers, P1003.1b-1993, p. 267 */
  169.  
  170. int _EXFUN(timer_settime,
  171.         (timer_t timerid, int flags,
  172.         const struct itimerspec *__restrict value,
  173.         struct itimerspec *__restrict ovalue));
  174. int _EXFUN(timer_gettime, (timer_t timerid, struct itimerspec *value));
  175. int _EXFUN(timer_getoverrun, (timer_t timerid));
  176.  
  177. /* High Resolution Sleep, P1003.1b-1993, p. 269 */
  178.  
  179. int _EXFUN(nanosleep, (const struct timespec  *rqtp, struct timespec *rmtp));
  180.  
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. #endif /* _POSIX_TIMERS */
  185.  
  186. #if defined(_POSIX_CLOCK_SELECTION)
  187.  
  188. #ifdef __cplusplus
  189. extern "C" {
  190. #endif
  191.  
  192. int _EXFUN(clock_nanosleep,
  193.   (clockid_t clock_id, int flags, const struct timespec *rqtp,
  194.    struct timespec *rmtp));
  195.  
  196. #ifdef __cplusplus
  197. }
  198. #endif
  199.  
  200. #endif /* _POSIX_CLOCK_SELECTION */
  201.  
  202. #ifdef __cplusplus
  203. extern "C" {
  204. #endif
  205.  
  206. /* CPU-time Clock Attributes, P1003.4b/D8, p. 54 */
  207.  
  208. /* values for the clock enable attribute */
  209.  
  210. #define CLOCK_ENABLED  1  /* clock is enabled, i.e. counting execution time */
  211. #define CLOCK_DISABLED 0  /* clock is disabled */
  212.  
  213. /* values for the pthread cputime_clock_allowed attribute */
  214.  
  215. #define CLOCK_ALLOWED    1 /* If a thread is created with this value a */
  216.                            /*   CPU-time clock attached to that thread */
  217.                            /*   shall be accessible. */
  218. #define CLOCK_DISALLOWED 0 /* If a thread is created with this value, the */
  219.                            /*   thread shall not have a CPU-time clock */
  220.                            /*   accessible. */
  221.  
  222. /* Manifest Constants, P1003.1b-1993, p. 262 */
  223.  
  224. #define CLOCK_REALTIME (clockid_t)1
  225.  
  226. /* Flag indicating time is "absolute" with respect to the clock
  227.    associated with a time.  */
  228.  
  229. #define TIMER_ABSTIME   4
  230.  
  231. /* Manifest Constants, P1003.4b/D8, p. 55 */
  232.  
  233. #if defined(_POSIX_CPUTIME)
  234.  
  235. /* When used in a clock or timer function call, this is interpreted as
  236.    the identifier of the CPU_time clock associated with the PROCESS
  237.    making the function call.  */
  238.  
  239. #define CLOCK_PROCESS_CPUTIME_ID (clockid_t)2
  240.  
  241. #endif
  242.  
  243. #if defined(_POSIX_THREAD_CPUTIME)
  244.  
  245. /*  When used in a clock or timer function call, this is interpreted as
  246.     the identifier of the CPU_time clock associated with the THREAD
  247.     making the function call.  */
  248.  
  249. #define CLOCK_THREAD_CPUTIME_ID (clockid_t)3
  250.  
  251. #endif
  252.  
  253. #if defined(_POSIX_MONOTONIC_CLOCK)
  254.  
  255. /*  The identifier for the system-wide monotonic clock, which is defined
  256.  *      as a clock whose value cannot be set via clock_settime() and which
  257.  *          cannot have backward clock jumps. */
  258.  
  259. #define CLOCK_MONOTONIC (clockid_t)4
  260.  
  261. #endif
  262.  
  263. #if defined(_POSIX_CPUTIME)
  264.  
  265. /* Accessing a Process CPU-time CLock, P1003.4b/D8, p. 55 */
  266.  
  267. int _EXFUN(clock_getcpuclockid, (pid_t pid, clockid_t *clock_id));
  268.  
  269. #endif /* _POSIX_CPUTIME */
  270.  
  271. #if defined(_POSIX_CPUTIME) || defined(_POSIX_THREAD_CPUTIME)
  272.  
  273. /* CPU-time Clock Attribute Access, P1003.4b/D8, p. 56 */
  274.  
  275. int _EXFUN(clock_setenable_attr, (clockid_t clock_id, int attr));
  276. int _EXFUN(clock_getenable_attr, (clockid_t clock_id, int *attr));
  277.  
  278. #endif /* _POSIX_CPUTIME or _POSIX_THREAD_CPUTIME */
  279.  
  280. #ifdef __cplusplus
  281. }
  282. #endif
  283.  
  284. #endif /* _TIME_H_ */
  285.  
  286.