Unify the example programs' termination

This is done to account for platforms, for which we want custom behavior
upon the program termination, hence we call `mbedtls_exit()` instead of
returning from `main()`.

For the sake of consistency, introduces the modifications have been made
to the test and utility examples as well. These, while less likely to be
used in the low level environments, won't suffer from such a change.
This commit is contained in:
Krzysztof Stachowiak 2019-04-24 14:24:46 +02:00 committed by Gilles Peskine
parent 0e08fff32f
commit a08652233d
47 changed files with 164 additions and 122 deletions

View file

@ -32,6 +32,7 @@
#include <stdlib.h>
#define mbedtls_fprintf fprintf
#define mbedtls_printf printf
#define mbedtls_exit exit
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
#endif /* MBEDTLS_PLATFORM_C */
@ -46,7 +47,7 @@
int main( void )
{
mbedtls_printf("MBEDTLS_ENTROPY_C and/or MBEDTLS_FS_IO not defined.\n");
return( 0 );
mbedtls_exit( 0 );
}
#else
int main( int argc, char *argv[] )
@ -60,13 +61,13 @@ int main( int argc, char *argv[] )
if( argc < 2 )
{
mbedtls_fprintf( stderr, "usage: %s <output filename>\n", argv[0] );
return( exit_code );
mbedtls_exit( exit_code );
}
if( ( f = fopen( argv[1], "wb+" ) ) == NULL )
{
mbedtls_printf( "failed to open '%s' for writing.\n", argv[1] );
return( exit_code );
mbedtls_exit( exit_code );
}
mbedtls_entropy_init( &entropy );
@ -96,6 +97,6 @@ cleanup:
fclose( f );
mbedtls_entropy_free( &entropy );
return( exit_code );
mbedtls_exit( exit_code );
}
#endif /* MBEDTLS_ENTROPY_C */