blob: 559734a6af46f4d7a34ce3f9a27cebb51a950c2c [file] [log] [blame]
Gilles Peskinec0a562c2025-07-25 17:07:13 +02001/* -*-c-*-
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +02002 * Query Mbed TLS compile time configurations from mbedtls_config.h
Andres Amaya Garcia88121a92018-10-16 22:00:13 +01003 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Andres Amaya Garcia88121a92018-10-16 22:00:13 +01006 */
7
Bence Szépkútic662b362021-05-27 11:25:03 +02008#include "mbedtls/build_info.h"
Andres Amaya Garcia88121a92018-10-16 22:00:13 +01009
Gilles Peskinec772b182021-01-12 15:55:10 +010010#include "query_config.h"
11
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010012#include "mbedtls/platform.h"
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010013#include <string.h>
14
Gilles Peskinec0a562c2025-07-25 17:07:13 +020015INCLUDE_HEADERS
16
Andres Amaya Garcia27b33722018-12-05 10:47:31 +000017/*
18 * Helper macros to convert a macro or its expansion into a string
19 * WARNING: This does not work for expanding function-like macros. However,
20 * Mbed TLS does not currently have configuration options used in this fashion.
21 */
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010022#define MACRO_EXPANSION_TO_STR(macro) MACRO_NAME_TO_STR(macro)
Andres Amaya Garcia27b33722018-12-05 10:47:31 +000023#define MACRO_NAME_TO_STR(macro) \
Gilles Peskine449bd832023-01-11 14:50:10 +010024 mbedtls_printf("%s", strlen( #macro "") > 0 ? #macro "\n" : "")
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010025
Jerry Yu2e8b0012021-12-10 20:29:02 +080026#define STRINGIFY(macro) #macro
Jerry Yu84e63a72021-12-06 13:40:37 +080027#define OUTPUT_MACRO_NAME_VALUE(macro) mbedtls_printf( #macro "%s\n", \
Gilles Peskine449bd832023-01-11 14:50:10 +010028 (STRINGIFY(macro) "")[0] != 0 ? "=" STRINGIFY( \
29 macro) : "")
Jerry Yu84e63a72021-12-06 13:40:37 +080030
Andres Amaya Garcia17c53c52019-01-24 09:55:14 +000031#if defined(_MSC_VER)
32/*
33 * Visual Studio throws the warning 4003 because many Mbed TLS feature macros
34 * are defined empty. This means that from the preprocessor's point of view
35 * the macro MBEDTLS_EXPANSION_TO_STR is being invoked without arguments as
36 * some macros expand to nothing. We suppress that specific warning to get a
37 * clean build and to ensure that tests treating warnings as errors do not
38 * fail.
39 */
40#pragma warning(push)
41#pragma warning(disable:4003)
42#endif /* _MSC_VER */
43
Gilles Peskine449bd832023-01-11 14:50:10 +010044int query_config(const char *config)
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010045{
Gilles Peskine449bd832023-01-11 14:50:10 +010046 CHECK_CONFIG /* If the symbol is not found, return an error */
47 return 1;
Andres Amaya Garcia88121a92018-10-16 22:00:13 +010048}
Andres Amaya Garcia17c53c52019-01-24 09:55:14 +000049
Gilles Peskine449bd832023-01-11 14:50:10 +010050void list_config(void)
Jerry Yu84e63a72021-12-06 13:40:37 +080051{
52 LIST_CONFIG
53}
Andres Amaya Garcia17c53c52019-01-24 09:55:14 +000054#if defined(_MSC_VER)
55#pragma warning(pop)
56#endif /* _MSC_VER */