1 #ifndef CYGONCE_LIBC_TIME_INL
2 #define CYGONCE_LIBC_TIME_INL
3 //===========================================================================
7 // Inline implementations of date and time routines from <time.h>
9 //===========================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //===========================================================================
43 //#####DESCRIPTIONBEGIN####
45 // Author(s): jlarmour
48 // Purpose: Provide inline implementations for some of the date and time
49 // routines declared in <time.h> for ISO C section 7.12 and
50 // POSIX 1003.1 8.3.4-8.3.7
52 // Usage: Do not include this file directly. Instead include <time.h>
54 //####DESCRIPTIONEND####
56 //===========================================================================
60 #include <pkgconf/libc_time.h> // C library configuration
64 #include <cyg/infra/cyg_type.h> // Common type definitions and support
65 #include <time.h> // Header for this file
66 #include <cyg/infra/cyg_ass.h> // Assertion infrastructure
67 #include <cyg/infra/cyg_trac.h> // Tracing infrastructure
71 // The following are overriden by the libc implementation to get a non-inline
72 // version to prevent duplication of code
74 #ifndef CYGPRI_LIBC_TIME_ASCTIME_R_INLINE
75 # define CYGPRI_LIBC_TIME_ASCTIME_R_INLINE extern __inline__
78 #ifndef CYGPRI_LIBC_TIME_CTIME_R_INLINE
79 # define CYGPRI_LIBC_TIME_CTIME_R_INLINE extern __inline__
82 #ifndef CYGPRI_LIBC_TIME_GMTIME_R_INLINE
83 # define CYGPRI_LIBC_TIME_GMTIME_R_INLINE extern __inline__
86 #ifndef CYGPRI_LIBC_TIME_LOCALTIME_R_INLINE
87 # define CYGPRI_LIBC_TIME_LOCALTIME_R_INLINE extern __inline__
90 #ifndef CYGPRI_LIBC_TIME_DIFFTIME_INLINE
91 # define CYGPRI_LIBC_TIME_DIFFTIME_INLINE extern __inline__
94 #ifndef CYGPRI_LIBC_TIME_MKTIME_INLINE
95 # define CYGPRI_LIBC_TIME_MKTIME_INLINE extern __inline__
98 #ifndef CYGPRI_LIBC_TIME_ASCTIME_INLINE
99 # define CYGPRI_LIBC_TIME_ASCTIME_INLINE extern __inline__
102 #ifndef CYGPRI_LIBC_TIME_CTIME_INLINE
103 # define CYGPRI_LIBC_TIME_CTIME_INLINE extern __inline__
106 #ifndef CYGPRI_LIBC_TIME_GMTIME_INLINE
107 # define CYGPRI_LIBC_TIME_GMTIME_INLINE extern __inline__
110 #ifndef CYGPRI_LIBC_TIME_LOCALTIME_INLINE
111 # define CYGPRI_LIBC_TIME_LOCALTIME_INLINE extern __inline__
114 #ifndef CYGPRI_LIBC_TIME_GETZONEOFFSETS_INLINE
115 # define CYGPRI_LIBC_TIME_GETZONEOFFSETS_INLINE extern __inline__
118 #ifndef CYGPRI_LIBC_TIME_SETZONEOFFSETS_INLINE
119 # define CYGPRI_LIBC_TIME_SETZONEOFFSETS_INLINE extern __inline__
122 #ifndef CYGPRI_LIBC_TIME_SETDST_INLINE
123 # define CYGPRI_LIBC_TIME_SETDST_INLINE extern __inline__
126 #define CYGNUM_LIBC_TIME_EPOCH_WDAY 4 // Jan 1st 1970 was a Thursday
134 // These are used in the dst access functions below. Do not access these
135 // directly - use the functions declared in time.h instead
137 extern Cyg_libc_time_dst cyg_libc_time_current_dst_stat;
138 extern time_t cyg_libc_time_current_std_offset;
139 extern time_t cyg_libc_time_current_dst_offset;
143 //===========================================================================
147 //////////////////////////////////
148 // cyg_libc_time_year_is_leap() //
149 //////////////////////////////////
151 // This returns true if the year is a leap year.
152 // The argument is of type int in line with struct tm
155 static __inline__ cyg_bool
156 cyg_libc_time_year_is_leap( int __year )
158 cyg_bool _leap=false;
162 else if (!(__year % 4) && (__year % 100))
165 } // cyg_libc_time_year_is_leap()
168 ////////////////////////////////////
169 // cyg_libc_time_getzoneoffsets() //
170 ////////////////////////////////////
172 // This function retrieves the current state of the Daylight Savings Time
173 // and the offsets of both STD and DST
174 // The offsets are both in time_t's i.e. seconds
177 CYGPRI_LIBC_TIME_GETZONEOFFSETS_INLINE Cyg_libc_time_dst
178 cyg_libc_time_getzoneoffsets( time_t *__stdoffset, time_t *__dstoffset )
180 CYG_REPORT_FUNCNAMETYPE("cyg_libc_time_getzoneoffsets",
181 "returning DST state %d");
182 CYG_REPORT_FUNCARG2("__stdoffset is at address %08x, "
183 "__dstoffset is at %08x", __stdoffset, __dstoffset);
185 CYG_CHECK_DATA_PTR(__stdoffset, "__stdoffset is not a valid pointer!");
186 CYG_CHECK_DATA_PTR(__dstoffset, "__dstoffset is not a valid pointer!");
188 *__stdoffset = cyg_libc_time_current_std_offset;
189 *__dstoffset = cyg_libc_time_current_dst_offset;
191 CYG_REPORT_RETVAL(cyg_libc_time_current_dst_stat);
193 return cyg_libc_time_current_dst_stat;
194 } // cyg_libc_time_getzoneoffsets()
197 ////////////////////////////////////
198 // cyg_libc_time_setzoneoffsets() //
199 ////////////////////////////////////
201 // This function sets the offsets used when Daylight Savings Time is enabled
202 // or disabled. The offsets are in time_t's i.e. seconds
205 CYGPRI_LIBC_TIME_SETZONEOFFSETS_INLINE void
206 cyg_libc_time_setzoneoffsets( time_t __stdoffset, time_t __dstoffset )
208 CYG_REPORT_FUNCNAME("cyg_libc_time_setzoneoffsets");
209 CYG_REPORT_FUNCARG2DV(__stdoffset, __dstoffset);
211 cyg_libc_time_current_std_offset = __stdoffset;
212 cyg_libc_time_current_dst_offset = __dstoffset;
215 } // cyg_libc_time_setzoneoffsets()
218 ////////////////////////////
219 // cyg_libc_time_setdst() //
220 ////////////////////////////
222 // This function sets the state of Daylight Savings Time: on, off, or unknown
225 CYGPRI_LIBC_TIME_SETDST_INLINE void
226 cyg_libc_time_setdst( Cyg_libc_time_dst __state )
228 CYG_REPORT_FUNCNAME("cyg_libc_time_setdst");
229 CYG_REPORT_FUNCARG1("__state=%d", __state);
231 cyg_libc_time_current_dst_stat = __state;
234 } // cyg_libc_time_setdst()
238 //===========================================================================
240 // POSIX 1003.1 functions
242 /////////////////////////////////
243 // asctime_r() - POSIX.1 8.3.4 //
244 /////////////////////////////////
246 // This returns a textual representation of a struct tm, and writes
247 // the string to return into __buf
250 #ifdef CYGFUN_LIBC_TIME_POSIX
251 # define __asctime_r asctime_r
253 // prototype internal function
255 __asctime_r( const struct tm *__timeptr, char *__buf );
258 #ifdef CYGIMP_LIBC_TIME_ASCTIME_R_INLINE
260 #include <cyg/libc/time/timeutil.h> // for cyg_libc_time_{day,month}_name
261 // and cyg_libc_time_itoa()
262 #include <string.h> // for memcpy()
264 CYGPRI_LIBC_TIME_ASCTIME_R_INLINE char *
265 __asctime_r( const struct tm *__timeptr, char *__buf )
269 // These initializers are [4] since C++ dictates you _must_ leave space
270 // for the trailing '\0', even though ISO C says you don't need to!
272 CYG_REPORT_FUNCNAMETYPE("asctime_r", "returning \"%s\"");
273 CYG_REPORT_FUNCARG2("__timeptr = %08x, __buf = %08x", __timeptr, __buf);
275 // paranoia - most of these aren't required but could be helpful to
276 // a programmer debugging their own app.
277 CYG_CHECK_DATA_PTR(__timeptr, "__timeptr is not a valid pointer!");
278 CYG_CHECK_DATA_PTR(__buf, "__buf is not a valid pointer!");
280 CYG_PRECONDITION((__timeptr->tm_sec >= 0) && (__timeptr->tm_sec < 62),
281 "__timeptr->tm_sec out of range!");
282 CYG_PRECONDITION((__timeptr->tm_min >= 0) && (__timeptr->tm_min < 60),
283 "__timeptr->tm_min out of range!");
284 CYG_PRECONDITION((__timeptr->tm_hour >= 0) && (__timeptr->tm_hour < 24),
285 "__timeptr->tm_hour out of range!");
286 // Currently I don't check _actual_ numbers of days in each month here
287 // FIXME: No reason why not though
288 CYG_PRECONDITION((__timeptr->tm_mday >= 1) && (__timeptr->tm_mday < 32),
289 "__timeptr->tm_mday out of range!");
290 CYG_PRECONDITION((__timeptr->tm_mon >= 0) && (__timeptr->tm_mon < 12),
291 "__timeptr->tm_mon out of range!");
292 CYG_PRECONDITION((__timeptr->tm_wday >= 0) && (__timeptr->tm_wday < 7),
293 "__timeptr->tm_wday out of range!");
294 CYG_PRECONDITION((__timeptr->tm_yday >= 0) && (__timeptr->tm_yday < 366),
295 "__timeptr->tm_yday out of range!");
296 CYG_PRECONDITION((__timeptr->tm_year > -1900) &&
297 (__timeptr->tm_year < 8100),
298 "__timeptr->tm_year out of range!");
300 // we can't use strftime because ISO C is stupid enough not to allow
301 // the strings in asctime() to be localized. Duh.
304 memcpy(&__buf[0], cyg_libc_time_day_name[__timeptr->tm_wday], 3);
308 memcpy(&__buf[4], cyg_libc_time_month_name[__timeptr->tm_mon], 3);
314 __i += cyg_libc_time_itoa( (cyg_uint8 *)&__buf[__i], __timeptr->tm_mday, 2,
319 __i += cyg_libc_time_itoa( (cyg_uint8 *)&__buf[__i], __timeptr->tm_hour, 2,
324 __i += cyg_libc_time_itoa( (cyg_uint8 *)&__buf[__i], __timeptr->tm_min, 2,
329 __i += cyg_libc_time_itoa((cyg_uint8 *) &__buf[__i], __timeptr->tm_sec, 2,
334 __i += cyg_libc_time_itoa( (cyg_uint8 *)&__buf[__i],
335 1900+__timeptr->tm_year, 0, true);
340 CYG_REPORT_RETVAL(__buf);
344 #endif // ifdef CYGIMP_LIBC_TIME_ASCTIME_R_INLINE
346 ////////////////////////////////
347 // gmtime_r() - POSIX.1 8.3.6 //
348 ////////////////////////////////
350 // This converts a time_t into a struct tm expressed in UTC, and stores
351 // the result in the space occupied by __result
354 #ifdef CYGFUN_LIBC_TIME_POSIX
355 # define __gmtime_r gmtime_r
357 // prototype internal function
358 __externC struct tm *
359 __gmtime_r( const time_t *__timer, struct tm *__result );
362 #ifdef CYGIMP_LIBC_TIME_GMTIME_R_INLINE
364 #include <cyg/libc/time/timeutil.h> // for cyg_libc_time_month_lengths
366 CYGPRI_LIBC_TIME_GMTIME_R_INLINE struct tm *
367 __gmtime_r( const time_t *__timer, struct tm *__result )
370 const cyg_uint8 *_months_p;
372 CYG_REPORT_FUNCNAMETYPE("gmtime_r", "returning %08x");
373 CYG_CHECK_DATA_PTR(__timer, "__timer is not a valid pointer!");
374 CYG_CHECK_DATA_PTR(__result, "__result is not a valid pointer!");
375 CYG_REPORT_FUNCARG2("*__timer=%d, __result is at %08x",
378 #define CYGNUM_LIBC_TIME_SECSPERDAY (60*60*24)
379 #define CYGNUM_LIBC_TIME_SECSPERYEAR (CYGNUM_LIBC_TIME_SECSPERDAY * 365)
380 #define CYGNUM_LIBC_TIME_SECSPERLEAPYEAR (CYGNUM_LIBC_TIME_SECSPERDAY * 366)
384 // First, work out year. Start off with 1970 and work forwards or backwards
385 // depending on the sign of _tim
386 __result->tm_year = 70;
388 // we also work out the day of the week of the start of the year as we
390 __result->tm_wday = CYGNUM_LIBC_TIME_EPOCH_WDAY;
397 // Check for a leap year.
398 if (cyg_libc_time_year_is_leap(1900 + __result->tm_year)) {
399 _tim += CYGNUM_LIBC_TIME_SECSPERLEAPYEAR;
400 __result->tm_wday -= 366;
403 _tim += CYGNUM_LIBC_TIME_SECSPERYEAR;
404 __result->tm_wday -= 365;
409 while (_tim >= CYGNUM_LIBC_TIME_SECSPERYEAR) {
412 if (cyg_libc_time_year_is_leap(1900 + __result->tm_year)) {
414 // But if this is a leap year, its possible that we are in the
415 // middle of the last "extra" day
416 if (_tim < CYGNUM_LIBC_TIME_SECSPERLEAPYEAR)
419 _tim -= CYGNUM_LIBC_TIME_SECSPERLEAPYEAR;
420 __result->tm_wday += 366;
423 _tim -= CYGNUM_LIBC_TIME_SECSPERYEAR;
424 __result->tm_wday += 365;
429 // Day of the year. We know _tim is +ve now
430 CYG_ASSERT(_tim >= 0,
431 "Number of seconds since start of year is negative!");
432 __result->tm_yday = _tim / CYGNUM_LIBC_TIME_SECSPERDAY;
434 // Day of the week. Normalize to be 0..6, and note that it might
435 // be negative, so we have to deal with the modulus being
436 // implementation-defined for -ve numbers (ISO C 6.3.5)
437 __result->tm_wday = (((__result->tm_wday + __result->tm_yday)%7)+7)%7;
439 // Month and Day of the month
441 _months_p = cyg_libc_time_month_lengths[
442 cyg_libc_time_year_is_leap(1900 + __result->tm_year) ? 1 : 0 ];
444 __result->tm_mday = __result->tm_yday+1;
446 for (__result->tm_mon = 0;
447 __result->tm_mday > _months_p[__result->tm_mon];
448 ++__result->tm_mon) {
450 __result->tm_mday -= _months_p[__result->tm_mon];
454 _tim -= __result->tm_yday*CYGNUM_LIBC_TIME_SECSPERDAY;
457 __result->tm_hour = (int) (_tim / 3600);
459 __result->tm_min = (int) (_tim / 60);
460 __result->tm_sec = (int) (_tim % 60);
462 __result->tm_isdst = 0; // gmtime always returns non-DST
464 CYG_REPORT_RETVAL(__result);
469 #endif // ifdef CYGIMP_LIBC_TIME_GMTIME_R_INLINE
471 ///////////////////////////////////
472 // localtime_r() - POSIX.1 8.3.7 //
473 ///////////////////////////////////
475 // This converts a time_t into a struct tm expressed in local time, and
476 // stores the result in the space occupied by __result
479 #ifdef CYGFUN_LIBC_TIME_POSIX
480 # define __localtime_r localtime_r
482 // prototype internal function
483 __externC struct tm *
484 __localtime_r( const time_t *__timer, struct tm *__result );
487 #ifdef CYGIMP_LIBC_TIME_LOCALTIME_R_INLINE
489 #include <cyg/libc/time/timeutil.h> // for cyg_libc_time_normalize_structtm()
491 CYGPRI_LIBC_TIME_LOCALTIME_R_INLINE struct tm *
492 __localtime_r( const time_t *__timer, struct tm *__result )
494 time_t __stdoffset, __dstoffset;
495 CYG_REPORT_FUNCNAMETYPE("localtime_r", "returning %08x");
496 CYG_CHECK_DATA_PTR(__timer, "__timer is not a valid pointer!");
497 CYG_CHECK_DATA_PTR(__result, "__result is not a valid pointer!");
498 CYG_REPORT_FUNCARG2("*__timer=%d, __result is at %08x",
501 __gmtime_r(__timer, __result);
503 // Adjust for STD/DST
504 __result->tm_isdst = cyg_libc_time_getzoneoffsets(&__stdoffset,
507 if (__result->tm_isdst == 0) { // STD
508 __result->tm_sec += __stdoffset;
509 cyg_libc_time_normalize_structtm( __result );
511 else if (__result->tm_isdst > 0) { // DST
512 __result->tm_sec += __dstoffset;
513 cyg_libc_time_normalize_structtm( __result );
515 // Don't do anything for tm_isdst == -1
517 CYG_REPORT_RETVAL(__result);
522 #endif // ifdef CYGIMP_LIBC_TIME_LOCALTIME_R_INLINE
525 ///////////////////////////////
526 // ctime_r() - POSIX.1 8.3.5 //
527 ///////////////////////////////
529 // This returns the equivalent of ctime() but writes to __buf
530 // to store the returned string
533 #ifdef CYGFUN_LIBC_TIME_POSIX
534 # define __ctime_r ctime_r
536 // prototype internal function
538 __ctime_r( const time_t *__timer, char *__buf );
541 #ifdef CYGIMP_LIBC_TIME_CTIME_R_INLINE
543 CYGPRI_LIBC_TIME_CTIME_R_INLINE char *
544 __ctime_r( const time_t *__timer, char *__buf )
548 CYG_REPORT_FUNCNAMETYPE("ctime_r", "returning \"%s\"");
550 CYG_CHECK_DATA_PTR(__timer, "__timer is not a valid pointer!");
551 CYG_CHECK_DATA_PTR(__buf, "__buf is not a valid pointer!");
553 CYG_REPORT_FUNCARG2("*__timer = %d, __buf=%08x", *__timer, __buf);
555 __localtime_r( __timer, &_mytm );
557 __asctime_r(&_mytm, __buf);
559 CYG_REPORT_RETVAL(__buf);
564 #endif // ifdef CYGIMP_LIBC_TIME_CTIME_R_INLINE
567 //===========================================================================
571 // Time manipulation functions - ISO C 7.12.2
573 /////////////////////////////////
574 // difftime() - ISO C 7.12.2.2 //
575 /////////////////////////////////
577 // This returns (__time1 - __time0) in seconds
580 #ifdef CYGIMP_LIBC_TIME_DIFFTIME_INLINE
582 CYGPRI_LIBC_TIME_DIFFTIME_INLINE double
583 difftime( time_t __time1, time_t __time0 )
587 CYG_REPORT_FUNCNAMETYPE("difftime", "returning %f");
588 CYG_REPORT_FUNCARG2("__time1=%d, __time0=%d", __time1, __time0);
590 _ret = (double)(__time1 - __time0);
592 CYG_REPORT_RETVAL(_ret);
597 #endif // ifdef CYGIMP_LIBC_TIME_DIFFTIME_INLINE
599 ///////////////////////////////
600 // mktime() - ISO C 7.12.2.3 //
601 ///////////////////////////////
603 // This converts a "struct tm" to a "time_t"
606 #ifdef CYGIMP_LIBC_TIME_MKTIME_INLINE
608 #include <cyg/libc/time/timeutil.h> // for cyg_libc_time_normalize_structtm()
609 // and cyg_libc_time_month_lengths
611 CYGPRI_LIBC_TIME_MKTIME_INLINE time_t
612 mktime( struct tm *__timeptr )
616 cyg_count32 _daycount;
619 CYG_REPORT_FUNCNAMETYPE("mktime", "returning %d");
620 CYG_REPORT_FUNCARG1( "__timeptr is at address %08x", __timeptr);
622 CYG_CHECK_DATA_PTR(__timeptr, "__timeptr is not a valid pointer!");
624 // First deal with STD/DST. If tm_isdst==-1 (the "autodetect" value)
625 // we assume its already in UTC. FIXME: is this correct behaviour? Hmm....
628 // FIXME: This doesn't seem to be the way to go
629 if (__timeptr->tm_isdst == 0) { // STD
630 // take _off_ the std offset to get us back to UTC from localtime
631 __timeptr->tm_sec -= (int)cyg_libc_time_current_std_offset;
633 else if (__timeptr->tm_isdst > 0) { // DST
634 // take _off_ the dst offset to get us back to UTC from localtime
635 __timeptr->tm_sec -= (int)cyg_libc_time_current_dst_offset;
639 cyg_libc_time_normalize_structtm(__timeptr);
641 // check if a time_t can hold the year. FIXME: we assume it is
642 // 32 bits which gives the year range 1902 - 2038
643 if ( (__timeptr->tm_year <= 2) || (__timeptr->tm_year >= 138) ) {
644 CYG_REPORT_RETVAL(-1);
648 // fill in the rest of the struct tm i.e. tm_wday and tm_yday
650 _leap = cyg_libc_time_year_is_leap(1900 + __timeptr->tm_year);
652 for (_i=0, _daycount=0; _i<12; ++_i) {
653 if (_i == __timeptr->tm_mon) {
654 _daycount += __timeptr->tm_mday - 1;
658 _daycount += cyg_libc_time_month_lengths[_leap][_i];
662 CYG_ASSERT(_i<12, "Reached end of year. __timeptr->tm_mon must be bad");
664 __timeptr->tm_yday = _daycount;
668 if (__timeptr->tm_year > 70) {
669 for (_i=70; _i < __timeptr->tm_year; ++_i)
670 _daycount += (cyg_libc_time_year_is_leap(1900 + _i) ? 366 : 365);
672 else if (__timeptr->tm_year < 70) {
673 for (_i=70; _i > __timeptr->tm_year; --_i)
674 _daycount -= (cyg_libc_time_year_is_leap(1900 + _i-1) ? 366 : 365);
677 __timeptr->tm_wday = (_daycount + CYGNUM_LIBC_TIME_EPOCH_WDAY) % 7;
679 // if _daycount was negative, on some targets the modulo operator will
680 // return negative, so we adjust for that
682 if (__timeptr->tm_wday < 0)
683 __timeptr->tm_wday += 7;
685 // now finally work out return value
687 _ret = __timeptr->tm_sec + 60*__timeptr->tm_min + 60*60*__timeptr->tm_hour;
688 _ret += _daycount*24*60*60;
690 CYG_REPORT_RETVAL(_ret);
695 #endif // ifdef CYGIMP_LIBC_TIME_MKTIME_INLINE
698 // Time conversion functions - ISO C 7.12.3
700 ////////////////////////////////
701 // asctime() - ISO C 7.12.3.1 //
702 ////////////////////////////////
704 // This returns a textual representation of a struct tm
707 #ifdef CYGIMP_LIBC_TIME_ASCTIME_INLINE
709 extern char cyg_libc_time_asctime_buf[];
711 CYGPRI_LIBC_TIME_ASCTIME_INLINE char *
712 asctime( const struct tm *__timeptr )
714 CYG_REPORT_FUNCNAMETYPE("__asctime", "returning \"%s\"");
715 CYG_REPORT_FUNCARG1("__timeptr = %08x", __timeptr);
718 CYG_CHECK_DATA_PTR(__timeptr, "__timeptr is not a valid pointer!");
720 (void)__asctime_r( __timeptr, cyg_libc_time_asctime_buf );
722 CYG_REPORT_RETVAL(cyg_libc_time_asctime_buf);
724 return cyg_libc_time_asctime_buf;
727 #endif // ifdef CYGIMP_LIBC_TIME_ASCTIME_INLINE
730 ///////////////////////////////
731 // gmtime() - ISO C 7.12.3.3 //
732 ///////////////////////////////
734 // This converts a time_t into a struct tm expressed in UTC
737 #ifdef CYGIMP_LIBC_TIME_GMTIME_INLINE
739 extern struct tm cyg_libc_time_gmtime_buf;
741 CYGPRI_LIBC_TIME_GMTIME_INLINE struct tm *
742 gmtime( const time_t *__timer )
744 CYG_REPORT_FUNCNAMETYPE("gmtime", "returning %08x");
745 CYG_CHECK_DATA_PTR(__timer, "__timer is not a valid pointer!");
746 CYG_REPORT_FUNCARG1("*__timer=%d", *__timer);
748 __gmtime_r(__timer, &cyg_libc_time_gmtime_buf);
750 CYG_REPORT_RETVAL(&cyg_libc_time_gmtime_buf);
752 return &cyg_libc_time_gmtime_buf;
755 #endif // ifdef CYGIMP_LIBC_TIME_GMTIME_INLINE
758 //////////////////////////////////
759 // localtime() - ISO C 7.12.3.4 //
760 //////////////////////////////////
762 // This converts a time_t into a struct tm expressed in local time
765 #ifdef CYGIMP_LIBC_TIME_LOCALTIME_INLINE
767 extern struct tm cyg_libc_time_localtime_buf;
769 CYGPRI_LIBC_TIME_LOCALTIME_INLINE struct tm *
770 localtime( const time_t *__timer )
772 CYG_REPORT_FUNCNAMETYPE("localtime", "returning %08x");
773 CYG_CHECK_DATA_PTR(__timer, "__timer is not a valid pointer!");
774 CYG_REPORT_FUNCARG1("*__timer=%d", *__timer);
776 __localtime_r(__timer, &cyg_libc_time_localtime_buf);
778 CYG_REPORT_RETVAL(&cyg_libc_time_localtime_buf);
780 return &cyg_libc_time_localtime_buf;
783 #endif // ifdef CYGIMP_LIBC_TIME_LOCALTIME_INLINE
786 //////////////////////////////
787 // ctime() - ISO C 7.12.3.2 //
788 //////////////////////////////
790 // This returns asctime(localtime(__timeptr))
793 #ifdef CYGIMP_LIBC_TIME_CTIME_INLINE
795 CYGPRI_LIBC_TIME_CTIME_INLINE char *
796 ctime( const time_t *__timer )
800 CYG_REPORT_FUNCNAMETYPE("ctime", "returning \"%s\"");
801 CYG_CHECK_DATA_PTR( __timer, "__timer is not a valid pointer!");
802 CYG_REPORT_FUNCARG1("*__timer = %d", *__timer);
804 _str = asctime(localtime(__timer));
806 CYG_REPORT_RETVAL(_str);
811 #endif // ifdef CYGIMP_LIBC_TIME_CTIME_INLINE
818 #endif // CYGONCE_LIBC_TIME_INL multiple inclusion protection