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:
parent
0e08fff32f
commit
a08652233d
47 changed files with 164 additions and 122 deletions
|
@ -26,6 +26,15 @@
|
|||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define mbedtls_printf printf
|
||||
#define mbedtls_exit exit
|
||||
#endif
|
||||
|
||||
/*
|
||||
* We're creating and connecting the socket "manually" rather than using the
|
||||
* NET module, in order to avoid the overhead of getaddrinfo() which tends to
|
||||
|
@ -44,28 +53,15 @@
|
|||
!defined(MBEDTLS_NET_C) || !defined(MBEDTLS_SSL_CLI_C) || \
|
||||
!defined(UNIX)
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif
|
||||
|
||||
int main( void )
|
||||
{
|
||||
mbedtls_printf( "MBEDTLS_CTR_DRBG_C and/or MBEDTLS_ENTROPY_C and/or "
|
||||
"MBEDTLS_NET_C and/or MBEDTLS_SSL_CLI_C and/or UNIX "
|
||||
"not defined.\n");
|
||||
return( 0 );
|
||||
mbedtls_exit( 0 );
|
||||
}
|
||||
#else
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
#include "mbedtls/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "mbedtls/net_sockets.h"
|
||||
|
@ -297,6 +293,6 @@ exit:
|
|||
mbedtls_x509_crt_free( &ca );
|
||||
#endif
|
||||
|
||||
return( ret );
|
||||
mbedtls_exit( ret );
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue