query_compile_time_config.c 2.4 KB

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