⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 time.inl

📁 ecos为实时嵌入式操作系统
💻 INL
📖 第 1 页 / 共 2 页
字号:
    for (__result->tm_mon = 0;         __result->tm_mday > _months_p[__result->tm_mon];         ++__result->tm_mon) {                __result->tm_mday -= _months_p[__result->tm_mon];    } // for    // The month day is now in the range 0..30    // We move it to 1..31    ++__result->tm_mday;        _tim -= __result->tm_yday*CYGNUM_LIBC_TIME_SECSPERDAY;    // hours, mins secs    __result->tm_hour = (int) (_tim / 3600);    _tim %= 3600;    __result->tm_min  = (int) (_tim / 60);    __result->tm_sec  = (int) (_tim % 60);    __result->tm_isdst = 0; // gmtime always returns non-DST    CYG_REPORT_RETVAL(__result);    return __result;} // __gmtime_r()# ifdef CYGFUN_LIBC_TIME_POSIX#  define gmtime_r(__timer, __result) __gmtime_r(__timer, __result)# endif#elseextern struct tm *__gmtime_r( const time_t *__timer, struct tm *__result );#endif // ifdef CYGIMP_LIBC_TIME_GMTIME_R_INLINE///////////////////////////////////// localtime_r() - POSIX.1 8.3.7 ///////////////////////////////////////// This converts a time_t into a struct tm expressed in local time, and// stores the result in the space occupied by __result//#ifdef CYGIMP_LIBC_TIME_LOCALTIME_R_INLINE#include <sys/timeutil.h>        // for cyg_libc_time_normalize_structtm()CYGPRI_LIBC_TIME_LOCALTIME_R_INLINE struct tm *__localtime_r( const time_t *__timer, struct tm *__result ){    time_t __stdoffset, __dstoffset;    CYG_REPORT_FUNCNAMETYPE("__localtime_r", "returning %08x");    CYG_CHECK_DATA_PTR(__timer, "__timer is not a valid pointer!");    CYG_CHECK_DATA_PTR(__result, "__result is not a valid pointer!");    CYG_REPORT_FUNCARG2("*__timer=%d, __result is at %08x",                        *__timer, __result);    __gmtime_r(__timer, __result);    // Adjust for STD/DST    __result->tm_isdst = cyg_libc_time_getzoneoffsets(&__stdoffset,                                                      &__dstoffset);    if (__result->tm_isdst == 0) { // STD        __result->tm_sec += __stdoffset;        cyg_libc_time_normalize_structtm( __result );    } // if    else if (__result->tm_isdst > 0) { // DST        __result->tm_sec += __dstoffset;        cyg_libc_time_normalize_structtm( __result );    } // if    // Don't do anything for tm_isdst == -1    CYG_REPORT_RETVAL(__result);    return __result;} // __localtime_r()# ifdef CYGFUN_LIBC_TIME_POSIX#  define localtime_r(__timer, __result) __localtime_r(__timer, __result)# endif#elseextern struct tm *__localtime_r( const time_t *__timer, struct tm *__result );#endif // ifdef CYGIMP_LIBC_TIME_LOCALTIME_R_INLINE///////////////////////////////// ctime_r() - POSIX.1 8.3.5 ///////////////////////////////////// This returns the equivalent of ctime() but writes to __buf// to store the returned string//#ifdef CYGIMP_LIBC_TIME_CTIME_R_INLINECYGPRI_LIBC_TIME_CTIME_R_INLINE char *__ctime_r( const time_t *__timer, char *__buf ){    struct tm _mytm;    CYG_REPORT_FUNCNAMETYPE("__ctime_r", "returning \"%s\"");    CYG_CHECK_DATA_PTR(__timer, "__timer is not a valid pointer!");    CYG_CHECK_DATA_PTR(__buf, "__buf is not a valid pointer!");    CYG_REPORT_FUNCARG2("*__timer = %d, __buf=%08x", *__timer, __buf);    __localtime_r( __timer, &_mytm );    __asctime_r(&_mytm, __buf);    CYG_REPORT_RETVAL(__buf);    return __buf;} // __ctime_r()# ifdef CYGFUN_LIBC_TIME_POSIX#  define ctime_r(__timer, __buf) __ctime_r(__timer, __buf)# endif#elseextern char *__ctime_r( const time_t *__timer, char *__buf );#endif // ifdef CYGIMP_LIBC_TIME_CTIME_R_INLINE//===========================================================================//// ISO C functions// Time manipulation functions - ISO C 7.12.2/////////////////////////////////// difftime() - ISO C 7.12.2.2 /////////////////////////////////////// This returns (__time1 - __time0) in seconds//#ifdef CYGIMP_LIBC_TIME_DIFFTIME_INLINECYGPRI_LIBC_TIME_DIFFTIME_INLINE double__difftime( time_t __time1, time_t __time0 ){    double _ret;        CYG_REPORT_FUNCNAMETYPE("__difftime", "returning %f");    CYG_REPORT_FUNCARG2("__time1=%d, __time0=%d", __time1, __time0);    _ret = (double)(__time1 - __time0);        CYG_REPORT_RETVAL(_ret);    return _ret;} // __difftime()# define difftime(__time1, __time0) __difftime(__time1, __time0)#elseextern double__difftime( time_t __time1, time_t __time0 );#endif // ifdef CYGIMP_LIBC_TIME_DIFFTIME_INLINE///////////////////////////////// mktime() - ISO C 7.12.2.3 ///////////////////////////////////// This converts a "struct tm" to a "time_t"//#ifdef CYGIMP_LIBC_TIME_MKTIME_INLINE#include <sys/timeutil.h>        // for cyg_libc_time_normalize_structtm()                                 // and cyg_libc_time_month_lengthsCYGPRI_LIBC_TIME_MKTIME_INLINE time_t__mktime( struct tm *__timeptr ){    time_t _ret;    cyg_count16 _i;    cyg_count32 _daycount;    cyg_bool _leap;    CYG_REPORT_FUNCNAMETYPE("__mktime", "returning %d");    CYG_REPORT_FUNCARG1( "__timeptr is at address %08x", __timeptr);    CYG_CHECK_DATA_PTR(__timeptr, "__timeptr is not a valid pointer!");    // First deal with STD/DST. If tm_isdst==-1 (the "autodetect" value)    // we assume its already in UTC. FIXME: is this correct behaviour? Hmm....#if 0// FIXME: This doesn't seem to be the way to go    if (__timeptr->tm_isdst == 0) { // STD        // take _off_ the std offset to get us back to UTC from localtime        __timeptr->tm_sec -= (int)cyg_libc_time_current_std_offset;    } // if    else if (__timeptr->tm_isdst > 0) { // DST        // take _off_ the dst offset to get us back to UTC from localtime        __timeptr->tm_sec -= (int)cyg_libc_time_current_dst_offset;    } // if#endif        cyg_libc_time_normalize_structtm(__timeptr);    // check if a time_t can hold the year. FIXME: we assume it is    // 32 bits which gives the year range 1902 - 2038    if ( (__timeptr->tm_year <= 2) || (__timeptr->tm_year >= 138) ) {        CYG_REPORT_RETVAL(-1);        return (time_t)-1;    }    // fill in the rest of the struct tm i.e. tm_wday and tm_yday        _leap = cyg_libc_time_year_is_leap(1900 + __timeptr->tm_year);    for (_i=0, _daycount=0; _i<12; ++_i) {        if (_i == __timeptr->tm_mon) {            _daycount += __timeptr->tm_mday - 1;            break;        } // if        else {            _daycount += cyg_libc_time_month_lengths[_leap][_i];        } // else    } // for    CYG_ASSERT(_i<12, "Reached end of year. __timeptr->tm_mon must be bad");    __timeptr->tm_yday = _daycount;        // now tm_wday    if (__timeptr->tm_year > 70) {        for (_i=70; _i < __timeptr->tm_year; ++_i)            _daycount += (cyg_libc_time_year_is_leap(1900 + _i) ? 366 : 365);    } // if    else if (__timeptr->tm_year < 70) {        for (_i=70; _i > __timeptr->tm_year; --_i)            _daycount -= (cyg_libc_time_year_is_leap(1900 + _i-1) ? 366 : 365);    } // else if    __timeptr->tm_wday = (_daycount + CYGNUM_LIBC_TIME_EPOCH_WDAY) % 7;    // if _daycount was negative, on some targets the modulo operator will    // return negative, so we adjust for that    if (__timeptr->tm_wday < 0)        __timeptr->tm_wday += 7;    // now finally work out return value    _ret = __timeptr->tm_sec + 60*__timeptr->tm_min + 60*60*__timeptr->tm_hour;    _ret += _daycount*24*60*60;        CYG_REPORT_RETVAL(_ret);    return _ret;} // __mktime()# define mktime(__timeptr) __mktime(__timeptr)#elseextern time_t__mktime( struct tm *__timeptr );#endif // ifdef CYGIMP_LIBC_TIME_MKTIME_INLINE// Time conversion functions - ISO C 7.12.3////////////////////////////////// asctime() - ISO C 7.12.3.1 ////////////////////////////////////// This returns a textual representation of a struct tm//#ifdef CYGIMP_LIBC_TIME_ASCTIME_INLINEextern char cyg_libc_time_asctime_buf[];CYGPRI_LIBC_TIME_ASCTIME_INLINE char *__asctime( const struct tm *__timeptr ){    CYG_REPORT_FUNCNAMETYPE("__asctime", "returning \"%s\"");    CYG_REPORT_FUNCARG1("__timeptr = %08x", __timeptr);    // paranoia    CYG_CHECK_DATA_PTR(__timeptr, "__timeptr is not a valid pointer!");    (void)__asctime_r( __timeptr, cyg_libc_time_asctime_buf );    CYG_REPORT_RETVAL(cyg_libc_time_asctime_buf);    return cyg_libc_time_asctime_buf;} // __asctime()# define asctime(__timeptr) __asctime(__timeptr)#elseextern char *__asctime( const struct tm *__timeptr );#endif // ifdef CYGIMP_LIBC_TIME_ASCTIME_INLINE///////////////////////////////// gmtime() - ISO C 7.12.3.3 ///////////////////////////////////// This converts a time_t into a struct tm expressed in UTC//#ifdef CYGIMP_LIBC_TIME_GMTIME_INLINEextern struct tm cyg_libc_time_gmtime_buf;CYGPRI_LIBC_TIME_GMTIME_INLINE struct tm *__gmtime( const time_t *__timer ){    CYG_REPORT_FUNCNAMETYPE("__gmtime", "returning %08x");    CYG_CHECK_DATA_PTR(__timer, "__timer is not a valid pointer!");    CYG_REPORT_FUNCARG1("*__timer=%d", *__timer);    __gmtime_r(__timer, &cyg_libc_time_gmtime_buf);    CYG_REPORT_RETVAL(&cyg_libc_time_gmtime_buf);    return &cyg_libc_time_gmtime_buf;} // __gmtime()# define gmtime(__timer) __gmtime(__timer)#elseextern struct tm *__gmtime( const time_t *__timer);#endif // ifdef CYGIMP_LIBC_TIME_GMTIME_INLINE//////////////////////////////////// localtime() - ISO C 7.12.3.4 //////////////////////////////////////// This converts a time_t into a struct tm expressed in local time//#ifdef CYGIMP_LIBC_TIME_LOCALTIME_INLINEextern struct tm cyg_libc_time_localtime_buf;CYGPRI_LIBC_TIME_LOCALTIME_INLINE struct tm *__localtime( const time_t *__timer ){    CYG_REPORT_FUNCNAMETYPE("__localtime", "returning %08x");    CYG_CHECK_DATA_PTR(__timer, "__timer is not a valid pointer!");    CYG_REPORT_FUNCARG1("*__timer=%d", *__timer);    __localtime_r(__timer, &cyg_libc_time_localtime_buf);    CYG_REPORT_RETVAL(&cyg_libc_time_localtime_buf);    return &cyg_libc_time_localtime_buf;} // __localtime()# define localtime(__timer) __localtime(__timer)#elseextern struct tm *__localtime( const time_t *__timer );#endif // ifdef CYGIMP_LIBC_TIME_LOCALTIME_INLINE//////////////////////////////// ctime() - ISO C 7.12.3.2 //////////////////////////////////// This returns asctime(localtime(__timeptr))//#ifdef CYGIMP_LIBC_TIME_CTIME_INLINECYGPRI_LIBC_TIME_CTIME_INLINE char *__ctime( const time_t *__timer ){    char *_str;    CYG_REPORT_FUNCNAMETYPE("__ctime", "returning \"%s\"");    CYG_CHECK_DATA_PTR( __timer, "__timer is not a valid pointer!");    CYG_REPORT_FUNCARG1("*__timer = %d", *__timer);    _str = __asctime(__localtime(__timer));    CYG_REPORT_RETVAL(_str);    return _str;} // __ctime()# define ctime(__timer) __ctime(__timer)#elseextern char *__ctime( const time_t *__timer );#endif // ifdef CYGIMP_LIBC_TIME_CTIME_INLINE#ifdef __cplusplus} // extern "C"#endif#endif // CYGONCE_LIBC_TIME_INL multiple inclusion protection// EOF time.inl

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -