query_compile_time_config.c (1946B)
1 /* 2 * Query the Mbed TLS compile time configuration 3 * 4 * Copyright The Mbed TLS Contributors 5 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 6 */ 7 8 #include "mbedtls/build_info.h" 9 10 #include "mbedtls/platform.h" 11 12 #define USAGE \ 13 "usage: %s [ -all | -any | -l ] <MBEDTLS_CONFIG> ...\n\n" \ 14 "This program takes command line arguments which correspond to\n" \ 15 "the string representation of Mbed TLS compile time configurations.\n\n" \ 16 "If \"--all\" and \"--any\" are not used, then, if all given arguments\n" \ 17 "are defined in the Mbed TLS build, 0 is returned; otherwise 1 is\n" \ 18 "returned. Macro expansions of configurations will be printed (if any).\n" \ 19 "-l\tPrint all available configuration.\n" \ 20 "-all\tReturn 0 if all configurations are defined. Otherwise, return 1\n" \ 21 "-any\tReturn 0 if any configuration is defined. Otherwise, return 1\n" \ 22 "-h\tPrint this usage\n" 23 24 #include <string.h> 25 #include "query_config.h" 26 27 int main(int argc, char *argv[]) 28 { 29 int i; 30 31 if (argc < 2 || strcmp(argv[1], "-h") == 0) { 32 mbedtls_printf(USAGE, argv[0]); 33 return MBEDTLS_EXIT_FAILURE; 34 } 35 36 if (strcmp(argv[1], "-l") == 0) { 37 list_config(); 38 return 0; 39 } 40 41 if (strcmp(argv[1], "-all") == 0) { 42 for (i = 2; i < argc; i++) { 43 if (query_config(argv[i]) != 0) { 44 return 1; 45 } 46 } 47 return 0; 48 } 49 50 if (strcmp(argv[1], "-any") == 0) { 51 for (i = 2; i < argc; i++) { 52 if (query_config(argv[i]) == 0) { 53 return 0; 54 } 55 } 56 return 1; 57 } 58 59 for (i = 1; i < argc; i++) { 60 if (query_config(argv[i]) != 0) { 61 return 1; 62 } 63 } 64 65 return 0; 66 }