From bf3c3fa122dc80b0d495dc80a616f393aadfdb16 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 25 Oct 2023 17:40:19 +0200 Subject: [PATCH] Define try_chdir everywhere Signed-off-by: Gilles Peskine --- tests/suites/host_test.function | 9 ++++++++- tests/suites/main_test.function | 4 +--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/suites/host_test.function b/tests/suites/host_test.function index 736883fe10..d8ff49ef17 100644 --- a/tests/suites/host_test.function +++ b/tests/suites/host_test.function @@ -442,7 +442,7 @@ static void write_outcome_result(FILE *outcome_file, * * Failures are silent. */ -static void try_chdir(const char *argv0) +static void try_chdir_if_supported(const char *argv0) { /* We might want to allow backslash as well, for Windows. But then we also * need to consider chdir() vs _chdir(), and different conventions @@ -467,6 +467,13 @@ static void try_chdir(const char *argv0) } mbedtls_free(path); } +#else /* MBEDTLS_HAVE_CHDIR */ +/* No chdir() or no support for parsing argv[0] on this platform. */ +static void try_chdir_if_supported(const char *argv0) +{ + (void) argv0; + return; +} #endif /* MBEDTLS_HAVE_CHDIR */ /** diff --git a/tests/suites/main_test.function b/tests/suites/main_test.function index eb74e8f0cc..6ab4a5618c 100644 --- a/tests/suites/main_test.function +++ b/tests/suites/main_test.function @@ -237,7 +237,6 @@ int main(int argc, const char *argv[]) #endif #endif -#ifdef MBEDTLS_HAVE_CHDIR /* Try changing to the directory containing the executable, if * using the default data file. This allows running the executable * from another directory (e.g. the project root) and still access @@ -249,8 +248,7 @@ int main(int argc, const char *argv[]) * test-specific files such as the outcome file, which is arguably * not desirable and should be fixed later. */ - try_chdir(argv[0]); -#endif /* MBEDTLS_HAVE_CHDIR */ + try_chdir_if_supported(argv[0]); int ret = mbedtls_test_platform_setup(); if (ret != 0) {