From 0e61c08c2b38eaf88f0d8078fbba41e63e1f00cf Mon Sep 17 00:00:00 2001 From: Wander Lairson Costa Date: Wed, 24 Jun 2020 13:32:12 +0000 Subject: [PATCH] Fix eina file thread test on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On windows, we try to open the "cmd.exe" file, but without the full path the test fails unless it runs from the system directory. We now use the full path to test the eina_file_open function. Reviewed-by: Stefan Schmidt Reviewed-by: Vincent Torri Reviewed-by: João Paulo Taylor Ienczak Zanette Differential Revision: https://phab.enlightenment.org/D12021 --- src/tests/eina/eina_test_file.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/tests/eina/eina_test_file.c b/src/tests/eina/eina_test_file.c index 0ed1c93d75..bcaff19e40 100644 --- a/src/tests/eina/eina_test_file.c +++ b/src/tests/eina/eina_test_file.c @@ -490,7 +490,29 @@ static void * _eina_test_file_thread(void *data EINA_UNUSED, Eina_Thread t EINA_UNUSED) { #ifdef _WIN32 - const char *filename = "cmd.exe"; + char filename[MAX_PATH]; + size_t len; + const char test_file[] = "cmd.exe"; + + fail_if(!GetSystemDirectoryA(filename, MAX_PATH)); + + len = strlen(filename); + + /* + * Check the buffer size. + * The system path length + path separator + length of the test_file + null terminator + * Must fit in MAX_PATH. + */ + fail_if(MAX_PATH < len + 1 + sizeof(test_file)); + + // append trailing directory separator if there isn't one + if (filename[len - 1] != '\\' && filename[len - 1] != '/') + { + filename[len] = '\\'; + filename[len + 1] = '\0'; + } + + strncat(filename, test_file, MAX_PATH - len - 2); #else const char *filename = "/bin/sh"; #endif