1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
/* ctime( const time_t * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#ifndef REGTEST
errno_t ctime_s( char * s, rsize_t maxsize, const time_t * timer )
{
struct tm tm;
if ( s == NULL || timer == NULL || maxsize < 26 || maxsize > RSIZE_MAX )
{
if ( s != NULL && maxsize > 0 && maxsize <= RSIZE_MAX )
{
s[0] = '\0';
}
_PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) );
return _PDCLIB_EINVAL;
}
return asctime_s( s, maxsize, localtime_s( timer, &tm ) );
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
#include <stdio.h>
int main( void )
{
#ifndef REGTEST
/* TODO: System Clock DST */
time_t t;
char s[27];
/* TODO: Constraint handling */
t = -2147483648l;
TESTCASE( ctime_s( s, 27, &t ) == 0 );
TESTCASE( strcmp( s, "Fri Dec 13 21:45:52 1901\n" ) == 0 );
t = 2147483647l;
TESTCASE( ctime_s( s, 27, &t ) == 0 );
TESTCASE( strcmp( s, "Tue Jan 19 04:14:07 2038\n" ) == 0 );
#endif
return TEST_RESULTS;
}
#endif
|