Beispiel #1
0
_WCRTLINK errno_t __F_NAME(asctime_s,_wasctime_s)( CHAR_TYPE *s,
                            rsize_t maxsize, const struct tm *timeptr )
/*********************************************************************/
{
    errno_t     rc = -1;
    char        *msg = NULL;

    // Verify runtime-constraints
    // s       not NULL
    // timeptr not NULL
    // 26 <= maxsize      <= RSIZE_MAX
    // 0  <= timeptr.year <= 9999
    if( __check_constraint_nullptr_msg( msg, s ) &&
        __check_constraint_nullptr_msg( msg, timeptr ) &&
        __check_constraint_maxsize_msg( msg, maxsize ) &&
        __check_constraint_a_gt_b_msg( msg, 26, maxsize ) &&
        __check_constraint_a_gt_b_msg( msg, 0, timeptr->tm_year ) &&
        __check_constraint_a_gt_b_msg( msg, timeptr->tm_year, 9999  ) ) {

        // Parameters validated, now call 'normal' _asctime
        __F_NAME(_asctime,__wasctime)( timeptr, s );
        rc = 0;
    }

    if( msg != NULL ) {
        // Runtime-constraint violated, store zero in receiving field if possible
        if( (s != NULL) && (maxsize > 0) && __lte_rsizmax( maxsize ) ) {
            *s = NULLCHAR;
        }
        // Now call the handler
        __rtct_fail( __func__, msg, NULL );
    }

    return( rc );
}
Beispiel #2
0
_WCRTLINK errno_t __F_NAME(ctime_s,_wctime_s)( CHAR_TYPE *s,
                           rsize_t maxsize, const time_t *timer )
/***************************************************************/
{
    errno_t     rc = -1;
    char        *msg = NULL;
    struct tm   tm;

    // Verify runtime-constraints
    // s     not NULL
    // timer not NULL
    // 26 <= maxsize <= RSIZE_MAX
    // localtime_s(...) not NULL
    if( __check_constraint_nullptr_msg( msg, s ) &&
        __check_constraint_nullptr_msg( msg, timer ) &&
        __check_constraint_maxsize_msg( msg, maxsize ) &&
        __check_constraint_a_gt_b_msg( msg, 26, maxsize ) &&
        __check_constraint_nullptr_msg( msg, localtime_s( timer, &tm ) ) ) {

        __F_NAME(_asctime,__wasctime)( &tm, s );
        rc = 0;
    }

    if( msg != NULL ) {
        // Runtime-constraint violated, store zero in receiving field if possible
        if( (s != NULL) && (maxsize > 0) && __lte_rsizmax( maxsize ) ) {
            *s = NULLCHAR;
        }
        // Now call the handler
        __rtct_fail( __func__, msg, NULL );
    }
    return( rc );
}