From bffb7819d2af14610965429bbe324673a87aa4ae Mon Sep 17 00:00:00 2001 From: Jehan Date: Mon, 22 Mar 2021 21:06:20 +0100 Subject: [PATCH] test: fix test binary build for Windows. realpath() doesn't exist on Windows. Replace it with _fullpath() which does the same thing, as far as I can see (at least for creating an absolute path, it doesn't seem to canonicalize the path, or the docs doesn't say it, yet since we are controlling the arguments from our CMake script, it's not a big problem anyway). This fixed the CI build for Windows failing with: > undefined reference to `realpath' --- test/uchardet-tests.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/uchardet-tests.c b/test/uchardet-tests.c index 26ea04c..7b50f7b 100644 --- a/test/uchardet-tests.c +++ b/test/uchardet-tests.c @@ -45,6 +45,13 @@ #define BUFFER_SIZE 65536 +#if defined(_WIN32) || defined(__CYGWIN__) +#define realpath(filename,unused) _fullpath(NULL, filename, 0) +#define SEP '\\' +#else +#define SEP '/' +#endif + void detect(FILE *fp, char **charset, char **lang) { @@ -116,13 +123,13 @@ main(int argc, char ** argv) path = realpath(filename, NULL); assert(path); - expected_charset = strrchr(path, '/'); + expected_charset = strrchr(path, SEP); assert(expected_charset); *expected_charset = '\0'; expected_charset++; expected_charset = strtok(expected_charset, "."); - expected_lang = strrchr(path, '/'); + expected_lang = strrchr(path, SEP); assert(expected_lang); expected_lang++;