Convert-Binary-C
view release on metacpan or search on metacpan
tests/include/pdclib/functions/_tzcode/_PDCLIB_mktime_tzname.c view on Meta::CPAN
/* _PDCLIB_mktime_tzname( struct state *, struct tm *, bool )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#ifndef REGTEST
#include "pdclib/_PDCLIB_tzcode.h"
/* Adapted from code provided by Robert Elz, who writes:
The "best" way to do mktime I think is based on an idea of Bob
Kridle's (so its said...) from a long time ago.
It does a binary search of the time_t space. Since time_t's are
just 32 bits, its a max of 32 iterations (even at 64 bits it
would still be very reasonable).
*/
#ifndef WRONG
#define WRONG (-1)
#endif
/* Normalize logic courtesy Paul Eggert. */
static bool increment_overflow32( int_fast32_t * lp, int m )
{
int_fast32_t const l = *lp;
if ( ( l >= 0 ) ? ( m > _PDCLIB_INT_FAST32_MAX - l ) : ( m < _PDCLIB_INT_FAST32_MIN - l ) )
{
return true;
}
*lp += m;
return false;
}
static bool normalize_overflow( int * tensptr, int * unitsptr, int base )
{
int tensdelta;
tensdelta = ( *unitsptr >= 0 ) ?
( *unitsptr / base ) :
( -1 - ( -1 - *unitsptr ) / base );
*unitsptr -= tensdelta * base;
return _PDCLIB_increment_overflow( tensptr, tensdelta );
}
static bool normalize_overflow32( int_fast32_t * tensptr, int * unitsptr, int base )
{
int tensdelta;
tensdelta = ( *unitsptr >= 0 ) ?
( *unitsptr / base ) :
( -1 - ( -1 - *unitsptr ) / base );
*unitsptr -= tensdelta * base;
return increment_overflow32( tensptr, tensdelta );
}
static int tmcomp( const struct tm * atmp, const struct tm * btmp )
{
int result;
if ( atmp->tm_year != btmp->tm_year )
{
return atmp->tm_year < btmp->tm_year ? -1 : 1;
}
if ( ( result = ( atmp->tm_mon - btmp->tm_mon ) ) == 0 &&
( result = ( atmp->tm_mday - btmp->tm_mday ) ) == 0 &&
( result = ( atmp->tm_hour - btmp->tm_hour ) ) == 0 &&
( result = ( atmp->tm_min - btmp->tm_min ) ) == 0 )
{
result = atmp->tm_sec - btmp->tm_sec;
}
( run in 0.820 second using v1.01-cache-2.11-cpan-96521ef73a4 )