Switch to the new code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/programs/x509/load_roots.c b/programs/x509/load_roots.c
index b8b0ecd..237bd7c 100644
--- a/programs/x509/load_roots.c
+++ b/programs/x509/load_roots.c
@@ -50,11 +50,11 @@
#if !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_FS_IO) || \
!defined(MBEDTLS_TIMING_C)
-int main( void )
+int main(void)
{
mbedtls_printf("MBEDTLS_X509_CRT_PARSE_C and/or MBEDTLS_FS_IO and/or "
- "MBEDTLS_TIMING_C not defined.\n");
- mbedtls_exit( 0 );
+ "MBEDTLS_TIMING_C not defined.\n");
+ mbedtls_exit(0);
}
#else
@@ -80,55 +80,51 @@
/*
* global options
*/
-struct options
-{
+struct options {
const char **filenames; /* NULL-terminated list of file names */
unsigned iterations; /* Number of iterations to time */
int prime_cache; /* Prime the disk read cache? */
} opt;
-int read_certificates( const char *const *filenames )
+int read_certificates(const char *const *filenames)
{
mbedtls_x509_crt cas;
int ret = 0;
const char *const *cur;
- mbedtls_x509_crt_init( &cas );
+ mbedtls_x509_crt_init(&cas);
- for( cur = filenames; *cur != NULL; cur++ )
- {
- ret = mbedtls_x509_crt_parse_file( &cas, *cur );
- if( ret != 0 )
- {
+ for (cur = filenames; *cur != NULL; cur++) {
+ ret = mbedtls_x509_crt_parse_file(&cas, *cur);
+ if (ret != 0) {
#if defined(MBEDTLS_ERROR_C) || defined(MBEDTLS_ERROR_STRERROR_DUMMY)
char error_message[200];
- mbedtls_strerror( ret, error_message, sizeof( error_message ) );
- printf( "\n%s: -0x%04x (%s)\n",
- *cur, (unsigned) -ret, error_message );
+ mbedtls_strerror(ret, error_message, sizeof(error_message));
+ printf("\n%s: -0x%04x (%s)\n",
+ *cur, (unsigned) -ret, error_message);
#else
- printf( "\n%s: -0x%04x\n",
- *cur, (unsigned) -ret );
+ printf("\n%s: -0x%04x\n",
+ *cur, (unsigned) -ret);
#endif
goto exit;
}
}
exit:
- mbedtls_x509_crt_free( &cas );
- return( ret == 0 );
+ mbedtls_x509_crt_free(&cas);
+ return ret == 0;
}
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
{
int exit_code = MBEDTLS_EXIT_FAILURE;
unsigned i, j;
struct mbedtls_timing_hr_time timer;
unsigned long ms;
- if( argc <= 1 )
- {
- mbedtls_printf( USAGE );
+ if (argc <= 1) {
+ mbedtls_printf(USAGE);
goto exit;
}
@@ -136,66 +132,61 @@
opt.iterations = DFL_ITERATIONS;
opt.prime_cache = DFL_PRIME_CACHE;
- for( i = 1; i < (unsigned) argc; i++ )
- {
+ for (i = 1; i < (unsigned) argc; i++) {
char *p = argv[i];
char *q = NULL;
- if( strcmp( p, "--" ) == 0 )
+ if (strcmp(p, "--") == 0) {
break;
- if( ( q = strchr( p, '=' ) ) == NULL )
+ }
+ if ((q = strchr(p, '=')) == NULL) {
break;
+ }
*q++ = '\0';
- for( j = 0; p + j < q; j++ )
- {
- if( argv[i][j] >= 'A' && argv[i][j] <= 'Z' )
+ for (j = 0; p + j < q; j++) {
+ if (argv[i][j] >= 'A' && argv[i][j] <= 'Z') {
argv[i][j] |= 0x20;
+ }
}
- if( strcmp( p, "iterations" ) == 0 )
- {
- opt.iterations = atoi( q );
- }
- else if( strcmp( p, "prime" ) == 0 )
- {
- opt.iterations = atoi( q ) != 0;
- }
- else
- {
- mbedtls_printf( "Unknown option: %s\n", p );
- mbedtls_printf( USAGE );
+ if (strcmp(p, "iterations") == 0) {
+ opt.iterations = atoi(q);
+ } else if (strcmp(p, "prime") == 0) {
+ opt.iterations = atoi(q) != 0;
+ } else {
+ mbedtls_printf("Unknown option: %s\n", p);
+ mbedtls_printf(USAGE);
goto exit;
}
}
- opt.filenames = (const char**) argv + i;
- if( *opt.filenames == 0 )
- {
- mbedtls_printf( "Missing list of certificate files to parse\n" );
+ opt.filenames = (const char **) argv + i;
+ if (*opt.filenames == 0) {
+ mbedtls_printf("Missing list of certificate files to parse\n");
goto exit;
}
- mbedtls_printf( "Parsing %u certificates", argc - i );
- if( opt.prime_cache )
- {
- if( ! read_certificates( opt.filenames ) )
+ mbedtls_printf("Parsing %u certificates", argc - i);
+ if (opt.prime_cache) {
+ if (!read_certificates(opt.filenames)) {
goto exit;
- mbedtls_printf( " " );
+ }
+ mbedtls_printf(" ");
}
- (void) mbedtls_timing_get_timer( &timer, 1 );
- for( i = 1; i <= opt.iterations; i++ )
- {
- if( ! read_certificates( opt.filenames ) )
+ (void) mbedtls_timing_get_timer(&timer, 1);
+ for (i = 1; i <= opt.iterations; i++) {
+ if (!read_certificates(opt.filenames)) {
goto exit;
- mbedtls_printf( "." );
+ }
+ mbedtls_printf(".");
}
- ms = mbedtls_timing_get_timer( &timer, 0 );
- mbedtls_printf( "\n%u iterations -> %lu ms\n", opt.iterations, ms );
+ ms = mbedtls_timing_get_timer(&timer, 0);
+ mbedtls_printf("\n%u iterations -> %lu ms\n", opt.iterations, ms);
exit_code = MBEDTLS_EXIT_SUCCESS;
exit:
- mbedtls_exit( exit_code );
+ mbedtls_exit(exit_code);
}
#endif /* necessary configuration */