1a8e1175bSopenharmony_ci/* 2a8e1175bSopenharmony_ci * Query the Mbed TLS compile time configuration 3a8e1175bSopenharmony_ci * 4a8e1175bSopenharmony_ci * Copyright The Mbed TLS Contributors 5a8e1175bSopenharmony_ci * SPDX-License-Identifier: Apache-2.0 6a8e1175bSopenharmony_ci * 7a8e1175bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); you may 8a8e1175bSopenharmony_ci * not use this file except in compliance with the License. 9a8e1175bSopenharmony_ci * You may obtain a copy of the License at 10a8e1175bSopenharmony_ci * 11a8e1175bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 12a8e1175bSopenharmony_ci * 13a8e1175bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 14a8e1175bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 15a8e1175bSopenharmony_ci * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16a8e1175bSopenharmony_ci * See the License for the specific language governing permissions and 17a8e1175bSopenharmony_ci * limitations under the License. 18a8e1175bSopenharmony_ci */ 19a8e1175bSopenharmony_ci 20a8e1175bSopenharmony_ci#include "mbedtls/build_info.h" 21a8e1175bSopenharmony_ci 22a8e1175bSopenharmony_ci#include "mbedtls/platform.h" 23a8e1175bSopenharmony_ci 24a8e1175bSopenharmony_ci#define USAGE \ 25a8e1175bSopenharmony_ci "usage: %s [ -all | -any | -l ] <MBEDTLS_CONFIG> ...\n\n" \ 26a8e1175bSopenharmony_ci "This program takes command line arguments which correspond to\n" \ 27a8e1175bSopenharmony_ci "the string representation of Mbed TLS compile time configurations.\n\n" \ 28a8e1175bSopenharmony_ci "If \"--all\" and \"--any\" are not used, then, if all given arguments\n" \ 29a8e1175bSopenharmony_ci "are defined in the Mbed TLS build, 0 is returned; otherwise 1 is\n" \ 30a8e1175bSopenharmony_ci "returned. Macro expansions of configurations will be printed (if any).\n" \ 31a8e1175bSopenharmony_ci "-l\tPrint all available configuration.\n" \ 32a8e1175bSopenharmony_ci "-all\tReturn 0 if all configurations are defined. Otherwise, return 1\n" \ 33a8e1175bSopenharmony_ci "-any\tReturn 0 if any configuration is defined. Otherwise, return 1\n" \ 34a8e1175bSopenharmony_ci "-h\tPrint this usage\n" 35a8e1175bSopenharmony_ci 36a8e1175bSopenharmony_ci#include <string.h> 37a8e1175bSopenharmony_ci#include "query_config.h" 38a8e1175bSopenharmony_ci 39a8e1175bSopenharmony_ciint main(int argc, char *argv[]) 40a8e1175bSopenharmony_ci{ 41a8e1175bSopenharmony_ci int i; 42a8e1175bSopenharmony_ci 43a8e1175bSopenharmony_ci if (argc < 2 || strcmp(argv[1], "-h") == 0) { 44a8e1175bSopenharmony_ci mbedtls_printf(USAGE, argv[0]); 45a8e1175bSopenharmony_ci return MBEDTLS_EXIT_FAILURE; 46a8e1175bSopenharmony_ci } 47a8e1175bSopenharmony_ci 48a8e1175bSopenharmony_ci if (strcmp(argv[1], "-l") == 0) { 49a8e1175bSopenharmony_ci list_config(); 50a8e1175bSopenharmony_ci return 0; 51a8e1175bSopenharmony_ci } 52a8e1175bSopenharmony_ci 53a8e1175bSopenharmony_ci if (strcmp(argv[1], "-all") == 0) { 54a8e1175bSopenharmony_ci for (i = 2; i < argc; i++) { 55a8e1175bSopenharmony_ci if (query_config(argv[i]) != 0) { 56a8e1175bSopenharmony_ci return 1; 57a8e1175bSopenharmony_ci } 58a8e1175bSopenharmony_ci } 59a8e1175bSopenharmony_ci return 0; 60a8e1175bSopenharmony_ci } 61a8e1175bSopenharmony_ci 62a8e1175bSopenharmony_ci if (strcmp(argv[1], "-any") == 0) { 63a8e1175bSopenharmony_ci for (i = 2; i < argc; i++) { 64a8e1175bSopenharmony_ci if (query_config(argv[i]) == 0) { 65a8e1175bSopenharmony_ci return 0; 66a8e1175bSopenharmony_ci } 67a8e1175bSopenharmony_ci } 68a8e1175bSopenharmony_ci return 1; 69a8e1175bSopenharmony_ci } 70a8e1175bSopenharmony_ci 71a8e1175bSopenharmony_ci for (i = 1; i < argc; i++) { 72a8e1175bSopenharmony_ci if (query_config(argv[i]) != 0) { 73a8e1175bSopenharmony_ci return 1; 74a8e1175bSopenharmony_ci } 75a8e1175bSopenharmony_ci } 76a8e1175bSopenharmony_ci 77a8e1175bSopenharmony_ci return 0; 78a8e1175bSopenharmony_ci} 79