From 39b75381cda71c65a84f18f8a90054abf1c5a237 Mon Sep 17 00:00:00 2001 From: Thomas Beutlich Date: Sun, 20 Oct 2024 22:33:57 +0200 Subject: [PATCH 1/2] refs #4473 Remove legacy behaviour --- Modelica/Resources/C-Sources/ModelicaInternal.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Modelica/Resources/C-Sources/ModelicaInternal.c b/Modelica/Resources/C-Sources/ModelicaInternal.c index 701cc0d3ed..7d7a01186d 100644 --- a/Modelica/Resources/C-Sources/ModelicaInternal.c +++ b/Modelica/Resources/C-Sources/ModelicaInternal.c @@ -30,6 +30,10 @@ */ /* Changelog: + Oct. 20, 2024: by Thomas Beutlich + Removed legacy behaviour in ModelicaInternal_stat for + MSVC Visual Studio >= 2015 (ticket #4473) + Jan. 15, 2024: by Thomas Beutlich Utilized ModelicaDuplicateString and ModelicaDuplicateStringWithErrorReturn (ticket #3686) @@ -402,10 +406,7 @@ static ModelicaFileType Internal_stat(_In_z_ const char* name) { struct _stat fileInfo; int statReturn = _stat(name, &fileInfo); if (0 != statReturn) { - /* For some reason _stat requires "a:\" and "a:\test1" but fails - * on "a:" and "a:\test1\", respectively. It could be handled in the - * Modelica code, but seems better to have it here. - */ + /* _stat requires "a:\" instead of "a:" */ const char* firstSlash = strpbrk(name, "/\\"); const char* firstColon = strchr(name, ':'); const char c = (NULL != firstColon) ? firstColon[1] : '\0'; @@ -419,6 +420,10 @@ static ModelicaFileType Internal_stat(_In_z_ const char* name) { free(nameTmp); } } +#if defined(_MSC_VER) && _MSC_VER >= 1900 + /* _stat accepts both "a:\dir" and "a:\dir\" */ +#else + /* _stat requires "a:\dir" instead of "a:\dir\" */ else if (NULL != firstSlash && len > 1 && ('/' == name[len - 1] || '\\' == name[len - 1])) { char* nameTmp = (char*)malloc(len*(sizeof(char))); @@ -429,6 +434,7 @@ static ModelicaFileType Internal_stat(_In_z_ const char* name) { free(nameTmp); } } +#endif } if ( statReturn != 0 ) { type = FileType_NoFile; From 68ba78975bd29e5995ebce2db9ac6e3d90caab35 Mon Sep 17 00:00:00 2001 From: Thomas Beutlich Date: Mon, 18 Nov 2024 16:53:45 +0100 Subject: [PATCH 2/2] Update Modelica/Resources/C-Sources/ModelicaInternal.c Co-authored-by: Hans Olsson --- Modelica/Resources/C-Sources/ModelicaInternal.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modelica/Resources/C-Sources/ModelicaInternal.c b/Modelica/Resources/C-Sources/ModelicaInternal.c index 7d7a01186d..fd52540c32 100644 --- a/Modelica/Resources/C-Sources/ModelicaInternal.c +++ b/Modelica/Resources/C-Sources/ModelicaInternal.c @@ -424,6 +424,7 @@ static ModelicaFileType Internal_stat(_In_z_ const char* name) { /* _stat accepts both "a:\dir" and "a:\dir\" */ #else /* _stat requires "a:\dir" instead of "a:\dir\" */ + /* required for VS 2013 and earlier */ else if (NULL != firstSlash && len > 1 && ('/' == name[len - 1] || '\\' == name[len - 1])) { char* nameTmp = (char*)malloc(len*(sizeof(char)));