Use platform layer in programs for consistency.

This commit is contained in:
Rich Evans 2015-01-19 14:26:37 +00:00 committed by Paul Bakker
parent e94e6e5b9c
commit f90016aade
48 changed files with 1572 additions and 1145 deletions

View file

@ -26,6 +26,15 @@
#include POLARSSL_CONFIG_FILE
#endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_printf printf
#define polarssl_fprintf fprintf
#define polarssl_malloc malloc
#define polarssl_free free
#endif
#include <string.h>
#include <stdio.h>
@ -37,7 +46,7 @@ int main( int argc, char *argv[] )
((void) argc);
((void) argv);
printf("POLARSSL_MD5_C and/or POLARSSL_FS_IO not defined.\n");
polarssl_printf("POLARSSL_MD5_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
#else
@ -46,10 +55,10 @@ static int md5_wrapper( char *filename, unsigned char *sum )
int ret = md5_file( filename, sum );
if( ret == 1 )
fprintf( stderr, "failed to open: %s\n", filename );
polarssl_fprintf( stderr, "failed to open: %s\n", filename );
if( ret == 2 )
fprintf( stderr, "failed to read: %s\n", filename );
polarssl_fprintf( stderr, "failed to read: %s\n", filename );
return( ret );
}
@ -63,9 +72,9 @@ static int md5_print( char *filename )
return( 1 );
for( i = 0; i < 16; i++ )
printf( "%02x", sum[i] );
polarssl_printf( "%02x", sum[i] );
printf( " %s\n", filename );
polarssl_printf( " %s\n", filename );
return( 0 );
}
@ -82,7 +91,7 @@ static int md5_check( char *filename )
if( ( f = fopen( filename, "rb" ) ) == NULL )
{
printf( "failed to open: %s\n", filename );
polarssl_printf( "failed to open: %s\n", filename );
return( 1 );
}
@ -127,7 +136,7 @@ static int md5_check( char *filename )
if( diff != 0 )
{
nb_err2++;
fprintf( stderr, "wrong checksum: %s\n", line + 34 );
polarssl_fprintf( stderr, "wrong checksum: %s\n", line + 34 );
}
n = sizeof( line );
@ -137,13 +146,13 @@ static int md5_check( char *filename )
if( nb_err1 != 0 )
{
printf( "WARNING: %d (out of %d) input files could "
polarssl_printf( "WARNING: %d (out of %d) input files could "
"not be read\n", nb_err1, nb_tot1 );
}
if( nb_err2 != 0 )
{
printf( "WARNING: %d (out of %d) computed checksums did "
polarssl_printf( "WARNING: %d (out of %d) computed checksums did "
"not match\n", nb_err2, nb_tot2 );
}
@ -156,11 +165,11 @@ int main( int argc, char *argv[] )
if( argc == 1 )
{
printf( "print mode: md5sum <file> <file> ...\n" );
printf( "check mode: md5sum -c <checksum file>\n" );
polarssl_printf( "print mode: md5sum <file> <file> ...\n" );
polarssl_printf( "check mode: md5sum -c <checksum file>\n" );
#if defined(_WIN32)
printf( "\n Press Enter to exit this program.\n" );
polarssl_printf( "\n Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif