Mercurial > ecos
comparison packages/language/c/libc/current/include/time.h @ 2:443894e2e912 ecos-v1_2_1-release
Block commit of eCos version 1.2.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 12:24:34 +0000 |
| parents | 3111d98ba7b3 |
| children | c38311975d4f |
comparison
equal
deleted
inserted
replaced
| 1:72f549f0d891 | 2:443894e2e912 |
|---|---|
| 2 #define CYGONCE_LIBC_TIME_H | 2 #define CYGONCE_LIBC_TIME_H |
| 3 //=========================================================================== | 3 //=========================================================================== |
| 4 // | 4 // |
| 5 // time.h | 5 // time.h |
| 6 // | 6 // |
| 7 // ANSI standard time routines defined in section 7.12 of the standard | 7 // Date and time routines from ISO C section 7.12 and POSIX 1003.1 |
| 8 // | 8 // |
| 9 //=========================================================================== | 9 //=========================================================================== |
| 10 //####COPYRIGHTBEGIN#### | 10 //####COPYRIGHTBEGIN#### |
| 11 // | 11 // |
| 12 // ------------------------------------------- | 12 // ------------------------------------------- |
| 22 // | 22 // |
| 23 // The Original Code is eCos - Embedded Cygnus Operating System, released | 23 // The Original Code is eCos - Embedded Cygnus Operating System, released |
| 24 // September 30, 1998. | 24 // September 30, 1998. |
| 25 // | 25 // |
| 26 // The Initial Developer of the Original Code is Cygnus. Portions created | 26 // The Initial Developer of the Original Code is Cygnus. Portions created |
| 27 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | 27 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
| 28 // ------------------------------------------- | 28 // ------------------------------------------- |
| 29 // | 29 // |
| 30 //####COPYRIGHTEND#### | 30 //####COPYRIGHTEND#### |
| 31 //=========================================================================== | 31 //=========================================================================== |
| 32 //#####DESCRIPTIONBEGIN#### | 32 //#####DESCRIPTIONBEGIN#### |
| 33 // | 33 // |
| 34 // Author(s): jlarmour | 34 // Author(s): jlarmour |
| 35 // Contributors: jlarmour@cygnus.co.uk | 35 // Contributors: jlarmour |
| 36 // Date: 1998-02-13 | 36 // Date: 1999-02-25 |
| 37 // Purpose: | 37 // Purpose: Provide definitions required by ISO C section 7.12 and |
| 38 // POSIX 1003.1 8.3.4-8.3.7 | |
| 38 // Description: | 39 // Description: |
| 39 // Usage: #include <time.h> | 40 // Usage: #include <time.h> |
| 40 // | 41 // |
| 41 //####DESCRIPTIONEND#### | 42 //####DESCRIPTIONEND#### |
| 42 // | 43 // |
| 43 //=========================================================================== | 44 //=========================================================================== |
| 44 | 45 |
| 45 // CONFIGURATION | 46 // CONFIGURATION |
| 46 | 47 |
| 47 #include <pkgconf/libc.h> // Configuration header | 48 #include <pkgconf/libc.h> // C library configuration |
| 48 | |
| 49 // Include the C library? | |
| 50 #ifdef CYGPKG_LIBC | |
| 51 | 49 |
| 52 // INCLUDES | 50 // INCLUDES |
| 53 | 51 |
| 54 #include <cyg/infra/cyg_type.h> // ECC common type definitions and support | 52 #include <cyg/infra/cyg_type.h> // Common type definitions and support |
| 55 #include <stddef.h> // NULL and size_t from compiler | 53 #include <stddef.h> // <time.h> is required to provide NULL |
| 54 // and size_t, so we get them from compiler | |
| 56 | 55 |
| 57 // CONSTANTS | 56 // CONSTANTS |
| 58 | 57 |
| 59 // What to divide clock_t by to get seconds (para 7.12.1) | 58 // What to divide clock_t by to get seconds (para 7.12.1) |
| 60 #define CLOCKS_PER_SEC 1000 | 59 // According to CAE XSH, Issue 4, V2, CLOCKS_PER_SEC must be 1 million on all |
| 60 // XSI-conformant systems | |
| 61 #define CLOCKS_PER_SEC 1000000 | |
| 61 | 62 |
| 62 // TYPE DEFINITIONS | 63 // TYPE DEFINITIONS |
| 63 | 64 |
| 64 // as per para 7.12.1 | 65 // Define clock_t as per ISO C para 7.12.1 |
| 66 // We make it very big since CLOCKS_PER_SEC is so large - this should last | |
| 67 // for 584942 years :-) An int32 would only last a little over an hour :-( | |
| 65 typedef cyg_int64 clock_t; | 68 typedef cyg_int64 clock_t; |
| 66 | 69 |
| 70 // Define time_t as per ISO C para 7.12.1 | |
| 71 // In the implementation we give it the meaning of seconds since the | |
| 72 // Epoch (00:00:00 GMT, 1970-01-01), but don't rely on this - always use | |
| 73 // the type opaquely | |
| 74 // A 32-bit value will overflow in the year 2038. Hopefully we will have | |
| 75 // moved forward from 32-bit CPUs by then, so making it a cyg_count* type | |
| 76 // may suffice ;-) | |
| 67 typedef cyg_count32 time_t; | 77 typedef cyg_count32 time_t; |
| 68 | 78 #define __time_t_defined // FIXME: this is temporary to stop newlib's |
| 79 // <sys/types.h> complaining. This should be resolved | |
| 80 // properly and a new <sys/types.h> provided | |
| 81 | |
| 82 // Define struct tm as per ISO C para 7.12.1 | |
| 69 struct tm { | 83 struct tm { |
| 70 int tm_sec; // seconds after the minute - [0..61] | 84 int tm_sec; // seconds after the minute - [0..61] |
| 85 // (note 61 allows for two leap seconds) | |
| 71 int tm_min; // minutes after the hour - [0..59] | 86 int tm_min; // minutes after the hour - [0..59] |
| 72 int tm_hour; // hours since midnight - [0..23] | 87 int tm_hour; // hours since midnight - [0..23] |
| 73 int tm_mday; // days of the month - [1..31] | 88 int tm_mday; // days of the month - [1..31] |
| 74 int tm_mon; // months since January - [0..11] | 89 int tm_mon; // months since January - [0..11] |
| 75 int tm_year; // years since 1900 | 90 int tm_year; // years since 1900 |
| 78 int tm_isdst; // Daylight Saving Time flag - positive if DST is in | 93 int tm_isdst; // Daylight Saving Time flag - positive if DST is in |
| 79 // effect, 0 if not in effect, and negative if the info | 94 // effect, 0 if not in effect, and negative if the info |
| 80 // is not available | 95 // is not available |
| 81 }; | 96 }; |
| 82 | 97 |
| 98 // The following struct is used by the implementation-defined functions | |
| 99 // to manipulate the Daylight Savings Time state | |
| 100 typedef enum { | |
| 101 CYG_LIBC_TIME_DSTNA = -1, | |
| 102 CYG_LIBC_TIME_DSTOFF = 0, | |
| 103 CYG_LIBC_TIME_DSTON = 1 | |
| 104 } Cyg_libc_time_dst; | |
| 105 | |
| 83 // FUNCTION PROTOTYPES | 106 // FUNCTION PROTOTYPES |
| 84 | 107 |
| 85 //=========================================================================== | 108 #ifdef __cplusplus |
| 86 | 109 extern "C" { |
| 87 // 7.12.2 Time manipulation functions | 110 #endif |
| 88 | 111 |
| 89 externC clock_t | 112 //=========================================================================== |
| 113 // | |
| 114 // POSIX 1003.1 functions | |
| 115 | |
| 116 #ifdef CYGFUN_LIBC_TIME_POSIX | |
| 117 | |
| 118 ///////////////////////////////// | |
| 119 // asctime_r() - POSIX.1 8.3.4 // | |
| 120 ///////////////////////////////// | |
| 121 // | |
| 122 // This returns a textual representation of a struct tm, and writes | |
| 123 // the string to return into __buf | |
| 124 // | |
| 125 | |
| 126 extern char * | |
| 127 asctime_r( const struct tm *__timeptr, char *__buf ); | |
| 128 | |
| 129 /////////////////////////////// | |
| 130 // ctime_r() - POSIX.1 8.3.5 // | |
| 131 /////////////////////////////// | |
| 132 // | |
| 133 // This returns the equivalent of ctime() but writes to __buf | |
| 134 // to store the returned string | |
| 135 // | |
| 136 | |
| 137 extern char * | |
| 138 ctime_r( const time_t *__timer, char *__buf ); | |
| 139 | |
| 140 //////////////////////////////// | |
| 141 // gmtime_r() - POSIX.1 8.3.6 // | |
| 142 //////////////////////////////// | |
| 143 // | |
| 144 // This converts a time_t into a struct tm expressed in UTC, and stores | |
| 145 // the result in the space occupied by __result | |
| 146 // | |
| 147 | |
| 148 extern struct tm * | |
| 149 gmtime_r( const time_t *__timer, struct tm *__result ); | |
| 150 | |
| 151 /////////////////////////////////// | |
| 152 // localtime_r() - POSIX.1 8.3.7 // | |
| 153 /////////////////////////////////// | |
| 154 // | |
| 155 // This converts a time_t into a struct tm expressed in local time, and | |
| 156 // stores the result in the space occupied by __result | |
| 157 // | |
| 158 | |
| 159 extern struct tm * | |
| 160 localtime_r( const time_t *__timer, struct tm *__result ); | |
| 161 | |
| 162 | |
| 163 #endif // ifdef CYGFUN_LIBC_TIME_POSIX | |
| 164 | |
| 165 //=========================================================================== | |
| 166 | |
| 167 // ISO C functions | |
| 168 | |
| 169 // Time manipulation functions - ISO C 7.12.2 | |
| 170 | |
| 171 ////////////////////////////// | |
| 172 // clock() - ISO C 7.12.2.1 // | |
| 173 ////////////////////////////// | |
| 174 // | |
| 175 // Returns processor time used in "clock"s. For a single process, | |
| 176 // multi-threaded system this will just be the time since booting | |
| 177 // | |
| 178 | |
| 179 extern clock_t | |
| 90 clock( void ); | 180 clock( void ); |
| 91 | 181 |
| 92 #endif // ifdef CYGPKG_LIBC | 182 ///////////////////////////////// |
| 183 // difftime() - ISO C 7.12.2.2 // | |
| 184 ///////////////////////////////// | |
| 185 // | |
| 186 // This returns (__time1 - __time0) in seconds | |
| 187 // | |
| 188 | |
| 189 extern double | |
| 190 difftime( time_t __time1, time_t __time0 ); | |
| 191 | |
| 192 /////////////////////////////// | |
| 193 // mktime() - ISO C 7.12.2.3 // | |
| 194 /////////////////////////////// | |
| 195 // | |
| 196 // This converts a "struct tm" to a "time_t" | |
| 197 // | |
| 198 | |
| 199 extern time_t | |
| 200 mktime( struct tm *__timeptr ); | |
| 201 | |
| 202 ///////////////////////////// | |
| 203 // time() - ISO C 7.12.2.4 // | |
| 204 ///////////////////////////// | |
| 205 // | |
| 206 // This returns calendar time as a time_t | |
| 207 // | |
| 208 | |
| 209 extern time_t | |
| 210 time( time_t *__timer ); | |
| 211 | |
| 212 // Time conversion functions - ISO C 7.12.3 | |
| 213 | |
| 214 //////////////////////////////// | |
| 215 // asctime() - ISO C 7.12.3.1 // | |
| 216 //////////////////////////////// | |
| 217 // | |
| 218 // This returns a textual representation of a struct tm | |
| 219 // | |
| 220 | |
| 221 extern char * | |
| 222 asctime( const struct tm *__timeptr ); | |
| 223 | |
| 224 ////////////////////////////// | |
| 225 // ctime() - ISO C 7.12.3.2 // | |
| 226 ////////////////////////////// | |
| 227 // | |
| 228 // This returns asctime(localtime(__timeptr)) | |
| 229 // | |
| 230 | |
| 231 extern char * | |
| 232 ctime( const time_t *__timer ); | |
| 233 | |
| 234 /////////////////////////////// | |
| 235 // gmtime() - ISO C 7.12.3.3 // | |
| 236 /////////////////////////////// | |
| 237 // | |
| 238 // This converts a time_t into a struct tm expressed in UTC | |
| 239 // | |
| 240 | |
| 241 extern struct tm * | |
| 242 gmtime( const time_t *__timer ); | |
| 243 | |
| 244 ////////////////////////////////// | |
| 245 // localtime() - ISO C 7.12.3.4 // | |
| 246 ////////////////////////////////// | |
| 247 // | |
| 248 // This converts a time_t into a struct tm expressed in local time | |
| 249 // | |
| 250 | |
| 251 extern struct tm * | |
| 252 localtime( const time_t *__timer ); | |
| 253 | |
| 254 ///////////////////////////////// | |
| 255 // strftime() - ISO C 7.12.3.5 // | |
| 256 ///////////////////////////////// | |
| 257 // | |
| 258 // This converts a string using format specifiers that signify various | |
| 259 // time-related quantities | |
| 260 // | |
| 261 | |
| 262 extern size_t | |
| 263 strftime( char *__s, size_t __maxsize, const char *__format, | |
| 264 const struct tm *__timeptr) CYGPRI_LIBC_ATTRIB_FORMAT_STRFTIME; | |
| 265 | |
| 266 //=========================================================================== | |
| 267 | |
| 268 // Implementation-specific functions | |
| 269 | |
| 270 //////////////////////////////////// | |
| 271 // cyg_libc_time_setzoneoffsets() // | |
| 272 //////////////////////////////////// | |
| 273 // | |
| 274 // This function sets the offsets used when Daylight Savings Time is enabled | |
| 275 // or disabled. The offsets are in time_t's | |
| 276 // | |
| 277 | |
| 278 extern void | |
| 279 cyg_libc_time_setzoneoffsets( time_t __stdoffset, time_t __dstoffset ); | |
| 280 | |
| 281 //////////////////////////// | |
| 282 // cyg_libc_time_setdst() // | |
| 283 //////////////////////////// | |
| 284 // | |
| 285 // This function sets the state of Daylight Savings Time: on, off, or unknown | |
| 286 // | |
| 287 | |
| 288 extern void | |
| 289 cyg_libc_time_setdst( Cyg_libc_time_dst __state ); | |
| 290 | |
| 291 | |
| 292 //////////////////////////////////// | |
| 293 // cyg_libc_time_getzoneoffsets() // | |
| 294 //////////////////////////////////// | |
| 295 // | |
| 296 // This function retrieves the current state of the Daylight Savings Time | |
| 297 // and the offsets of both STD and DST | |
| 298 // The offsets are both in time_t's | |
| 299 // | |
| 300 | |
| 301 extern Cyg_libc_time_dst | |
| 302 cyg_libc_time_getzoneoffsets( time_t *__stdoffset, time_t *__dstoffset ); | |
| 303 | |
| 304 ///////////////////////////// | |
| 305 // cyg_libc_time_settime() // | |
| 306 ///////////////////////////// | |
| 307 // | |
| 308 // This function sets the current time for the system. The time is | |
| 309 // specified as a time_t in UTC. It returns non-zero on error. | |
| 310 // | |
| 311 | |
| 312 extern cyg_bool | |
| 313 cyg_libc_time_settime( time_t __utctime ); | |
| 314 | |
| 315 | |
| 316 #ifdef __cplusplus | |
| 317 } // extern "C" | |
| 318 #endif | |
| 319 | |
| 320 #include <time.inl> | |
| 93 | 321 |
| 94 #endif // CYGONCE_LIBC_TIME_H multiple inclusion protection | 322 #endif // CYGONCE_LIBC_TIME_H multiple inclusion protection |
| 95 | 323 |
| 96 // EOF time.h | 324 // EOF time.h |
