time.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * time.h
  3. *
  4. * Date and time functions and types.
  5. *
  6. * This file is part of the Mingw32 package.
  7. *
  8. * Contributors:
  9. * Created by Colin Peters <[email protected]>
  10. *
  11. * THIS SOFTWARE IS NOT COPYRIGHTED
  12. *
  13. * This source code is offered for use in the public domain. You may
  14. * use, modify or distribute it freely.
  15. *
  16. * This code is distributed in the hope that it will be useful but
  17. * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  18. * DISCLAIMED. This includes but is not limited to warranties of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. * $Revision: 1.2 $
  22. * $Author: bellard $
  23. * $Date: 2005/04/17 13:14:29 $
  24. *
  25. */
  26. #ifndef _TIME_H_
  27. #define _TIME_H_
  28. /* All the headers include this file. */
  29. #include <_mingw.h>
  30. #define __need_wchar_t
  31. #define __need_size_t
  32. #ifndef RC_INVOKED
  33. #include <stddef.h>
  34. #endif /* Not RC_INVOKED */
  35. /*
  36. * Need a definition of time_t.
  37. */
  38. #include <sys/types.h>
  39. /*
  40. * Number of clock ticks per second. A clock tick is the unit by which
  41. * processor time is measured and is returned by 'clock'.
  42. */
  43. #define CLOCKS_PER_SEC ((clock_t)1000)
  44. #define CLK_TCK CLOCKS_PER_SEC
  45. #ifndef RC_INVOKED
  46. /*
  47. * A type for storing the current time and date. This is the number of
  48. * seconds since midnight Jan 1, 1970.
  49. * NOTE: Normally this is defined by the above include of sys/types.h
  50. */
  51. #ifndef _TIME_T_DEFINED
  52. typedef long time_t;
  53. #define _TIME_T_DEFINED
  54. #endif
  55. /*
  56. * A type for measuring processor time (in clock ticks).
  57. */
  58. #ifndef _CLOCK_T_DEFINED
  59. typedef long clock_t;
  60. #define _CLOCK_T_DEFINED
  61. #endif
  62. /*
  63. * A structure for storing all kinds of useful information about the
  64. * current (or another) time.
  65. */
  66. struct tm
  67. {
  68. int tm_sec; /* Seconds: 0-59 (K&R says 0-61?) */
  69. int tm_min; /* Minutes: 0-59 */
  70. int tm_hour; /* Hours since midnight: 0-23 */
  71. int tm_mday; /* Day of the month: 1-31 */
  72. int tm_mon; /* Months *since* january: 0-11 */
  73. int tm_year; /* Years since 1900 */
  74. int tm_wday; /* Days since Sunday (0-6) */
  75. int tm_yday; /* Days since Jan. 1: 0-365 */
  76. int tm_isdst; /* +1 Daylight Savings Time, 0 No DST,
  77. * -1 don't know */
  78. };
  79. #ifdef __cplusplus
  80. extern "C" {
  81. #endif
  82. clock_t clock (void);
  83. time_t time (time_t*);
  84. double difftime (time_t, time_t);
  85. time_t mktime (struct tm*);
  86. /*
  87. * These functions write to and return pointers to static buffers that may
  88. * be overwritten by other function calls. Yikes!
  89. *
  90. * NOTE: localtime, and perhaps the others of the four functions grouped
  91. * below may return NULL if their argument is not 'acceptable'. Also note
  92. * that calling asctime with a NULL pointer will produce an Invalid Page
  93. * Fault and crap out your program. Guess how I know. Hint: stat called on
  94. * a directory gives 'invalid' times in st_atime etc...
  95. */
  96. char* asctime (const struct tm*);
  97. char* ctime (const time_t*);
  98. struct tm* gmtime (const time_t*);
  99. struct tm* localtime (const time_t*);
  100. size_t strftime (char*, size_t, const char*, const struct tm*);
  101. size_t wcsftime (wchar_t*, size_t, const wchar_t*, const struct tm*);
  102. #ifndef __STRICT_ANSI__
  103. extern void _tzset (void);
  104. #ifndef _NO_OLDNAMES
  105. extern void tzset (void);
  106. #endif
  107. size_t strftime(char*, size_t, const char*, const struct tm*);
  108. char* _strdate(char*);
  109. char* _strtime(char*);
  110. #endif /* Not __STRICT_ANSI__ */
  111. /*
  112. * _daylight: non zero if daylight savings time is used.
  113. * _timezone: difference in seconds between GMT and local time.
  114. * _tzname: standard/daylight savings time zone names (an array with two
  115. * elements).
  116. */
  117. #ifdef __MSVCRT__
  118. /* These are for compatibility with pre-VC 5.0 suppied MSVCRT. */
  119. extern int* __p__daylight (void);
  120. extern long* __p__timezone (void);
  121. extern char** __p__tzname (void);
  122. __MINGW_IMPORT int _daylight;
  123. __MINGW_IMPORT long _timezone;
  124. __MINGW_IMPORT char *_tzname[2];
  125. #else /* not __MSVCRT (ie. crtdll) */
  126. #ifndef __DECLSPEC_SUPPORTED
  127. extern int* __imp__daylight_dll;
  128. extern long* __imp__timezone_dll;
  129. extern char** __imp__tzname;
  130. #define _daylight (*__imp__daylight_dll)
  131. #define _timezone (*__imp__timezone_dll)
  132. #define _tzname (__imp__tzname)
  133. #else /* __DECLSPEC_SUPPORTED */
  134. __MINGW_IMPORT int _daylight_dll;
  135. __MINGW_IMPORT long _timezone_dll;
  136. __MINGW_IMPORT char* _tzname[2];
  137. #define _daylight _daylight_dll
  138. #define _timezone _timezone_dll
  139. #endif /* __DECLSPEC_SUPPORTED */
  140. #endif /* not __MSVCRT__ */
  141. #ifndef _NO_OLDNAMES
  142. #ifdef __MSVCRT__
  143. /* These go in the oldnames import library for MSVCRT. */
  144. __MINGW_IMPORT int daylight;
  145. __MINGW_IMPORT long timezone;
  146. __MINGW_IMPORT char *tzname[2];
  147. #ifndef _WTIME_DEFINED
  148. /* wide function prototypes, also declared in wchar.h */
  149. wchar_t * _wasctime(const struct tm*);
  150. wchar_t * _wctime(const time_t*);
  151. wchar_t* _wstrdate(wchar_t*);
  152. wchar_t* _wstrtime(wchar_t*);
  153. #define _WTIME_DEFINED
  154. #endif /* _WTIME_DEFINED */
  155. #else /* not __MSVCRT__ */
  156. /* CRTDLL is royally messed up when it comes to these macros.
  157. TODO: import and alias these via oldnames import library instead
  158. of macros. */
  159. #define daylight _daylight
  160. /* NOTE: timezone not defined because it would conflict with sys/timeb.h.
  161. Also, tzname used to a be macro, but now it's in moldname. */
  162. __MINGW_IMPORT char *tzname[2];
  163. #endif /* not __MSVCRT__ */
  164. #endif /* Not _NO_OLDNAMES */
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168. #endif /* Not RC_INVOKED */
  169. #endif /* Not _TIME_H_ */