openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/shadow/4.6-r0/shadow-4.6/libmisc/strtoday.c
long strtoday(const char* str)
{
#ifdef HAVE_STRPTIME
    struct tm tp;
    char* const* fmt;
    char* cp;
    time_t result;

    memzero(&tp, sizeof tp);
    for (fmt = date_formats; *fmt; fmt++)
    {
        cp = strptime((char*)str, *fmt, &tp);
        if ((NULL == cp) || ('\0' != *cp))
        {
            continue;
        }

        result = mktime(&tp);
        if ((time_t)-1 == result)
        {
            continue;
        }

        return (long)(result / DAY); /* success */
    }
    return -1;
#else
    char slop[2];
    int month;
    int day;
    int year;
    long total;

    /*
     * start by separating the month, day and year.  the order
     * is compiled in ...
     */

    if (sscanf(str, "%d/%d/%d%c", &year, &month, &day, slop) != 3)
    {
        return -1;
    }

    /*
     * the month, day of the month, and year are checked for
     * correctness and the year adjusted so it falls between
     * 1970 and 2069.
     */

    if ((month < 1) || (month > 12))
    {
        return -1;
    }

    if (day < 1)
    {
        return -1;
    }

    if (((2 != month) || ((year % 4) != 0)) && (day > days[month]))
    {
        return -1;
    }
    else if ((month == 2) && ((year % 4) == 0) && (day > 29))
    {
        return -1;
    }

    if (year < 0)
    {
        return -1;
    }
    else if (year <= 69)
    {
        year += 2000;
    }
    else if (year <= 99)
    {
        year += 1900;
    }

    /*
     * On systems with 32-bit signed time_t, time wraps around in 2038
     * - for now we just limit the year to 2037 (instead of 2069).
     * This limit can be removed once no one is using 32-bit systems
     * anymore :-).  --marekm
     */
    if ((year < 1970) || (year > 2037))
    {
        return -1;
    }

    /*
     * the total number of days is the total number of days in all
     * the whole years, plus the number of leap days, plus the
     * number of days in the whole months preceding, plus the number
     * of days so far in the month.
     */

    total = (long)((year - 1970) * 365L) + (((year + 1) - 1970) / 4);
    total += (long)juldays[month] + (month > 2 && (year % 4) == 0 ? 1 : 0);
    total += (long)day - 1;

    return total;
#endif /* HAVE_STRPTIME */
}
/*
 * strtoday - compute the number of days since 1970.
 *
 * the total number of days prior to the current date is
 * computed.  january 1, 1970 is used as the origin with
 * it having a day number of 0.
 */
compute the number of days since 1970.
the total number of days prior to the current date is
computed.  january 1, 1970 is used as the origin with
it having a day number of 0.
compute the number of days since 1970 . the total number of days prior to the current date is computed . january 1 1970 is used as the origin with it having a day number of 0 .
long strtoday(const char* str)
{
#ifdef HAVE_STRPTIME
    struct tm tp;
    char* const* fmt;
    char* cp;
    time_t result;
    memzero(&tp, sizeof tp);
    for (fmt = date_formats; *fmt; fmt++)
    {
        cp = strptime((char*)str, *fmt, &tp);
        if ((NULL == cp) || ('\0' != *cp))
        {
            continue;
        }
        result = mktime(&tp);
        if ((time_t)-1 == result)
        {
            continue;
        }
        return (long)(result / DAY); 
    }
    return -1;
#else
    char slop[2];
    int month;
    int day;
    int year;
    long total;
    if (sscanf(str, "%d/%d/%d%c", &year, &month, &day, slop) != 3)
    {
        return -1;
    }
    if ((month < 1) || (month > 12))
    {
        return -1;
    }
    if (day < 1)
    {
        return -1;
    }
    if (((2 != month) || ((year % 4) != 0)) && (day > days[month]))
    {
        return -1;
    }
    else if ((month == 2) && ((year % 4) == 0) && (day > 29))
    {
        return -1;
    }
    if (year < 0)
    {
        return -1;
    }
    else if (year <= 69)
    {
        year += 2000;
    }
    else if (year <= 99)
    {
        year += 1900;
    }
    if ((year < 1970) || (year > 2037))
    {
        return -1;
    }
    total = (long)((year - 1970) * 365L) + (((year + 1) - 1970) / 4);
    total += (long)juldays[month] + (month > 2 && (year % 4) == 0 ? 1 : 0);
    total += (long)day - 1;
    return total;
#endif 
}
long strtoday ( const char * str ) { #ifdef HAVE_STRPTIME struct tm tp ; char * const * fmt ; char * cp ; time_t result ; memzero ( & tp , sizeof tp ) ; for ( fmt = date_formats ; * fmt ; fmt ++ ) { cp = strptime ( ( char * ) str , * fmt , & tp ) ; if ( ( NULL == cp ) || ( ' \0 ' != * cp ) ) { continue ; } result = mktime ( & tp ) ; if ( ( time_t ) - 1 == result ) { continue ; } return ( long ) ( result / DAY ) ; } return -1 ; #else char slop [ 2 ] ; int month ; int day ; int year ; long total ; if ( sscanf ( str , " " , & year , & month , & day , slop ) != 3 ) { return -1 ; } if ( ( month < 1 ) || ( month > 12 ) ) { return -1 ; } if ( day < 1 ) { return -1 ; } if ( ( ( 2 != month ) || ( ( year % 4 ) != 0 ) ) && ( day > days [ month ] ) ) { return -1 ; } else if ( ( month == 2 ) && ( ( year % 4 ) == 0 ) && ( day > 29 ) ) { return -1 ; } if ( year < 0 ) { return -1 ; } else if ( year <= 69 ) { year += 2000 ; } else if ( year <= 99 ) { year += 1900 ; } if ( ( year < 1970 ) || ( year > 2037 ) ) { return -1 ; } total = ( long ) ( ( year - 1970 ) * 365L ) + ( ( ( year + 1 ) - 1970 ) / 4 ) ; total += ( long ) juldays [ month ] + ( month > 2 && ( year % 4 ) == 0 ? 1 : 0 ) ; total += ( long ) day - 1 ; return total ; #endif }
strtoday - compute the number of days since 1970.
 the total number of days prior to the current date is
 computed.
strtoday - compute the number of days since 1970 . the total number of days prior to the current date is computed .
/* success */ /*
     * start by separating the month, day and year.  the order
     * is compiled in ...
     */ /*
     * the month, day of the month, and year are checked for
     * correctness and the year adjusted so it falls between
     * 1970 and 2069.
     */ /*
     * On systems with 32-bit signed time_t, time wraps around in 2038
     * - for now we just limit the year to 2037 (instead of 2069).
     * This limit can be removed once no one is using 32-bit systems
     * anymore :-).  --marekm
     */ /*
     * the total number of days is the total number of days in all
     * the whole years, plus the number of leap days, plus the
     * number of days in the whole months preceding, plus the number
     * of days so far in the month.
     */ /* HAVE_STRPTIME */