Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove MSVC legacy behaviour in ModelicaInternal_stat #4483

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Modelica/Resources/C-Sources/ModelicaInternal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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';
Expand All @@ -419,6 +420,11 @@ 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\" */
beutlich marked this conversation as resolved.
Show resolved Hide resolved
/* 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)));
Expand All @@ -429,6 +435,7 @@ static ModelicaFileType Internal_stat(_In_z_ const char* name) {
free(nameTmp);
}
}
#endif
}
if ( statReturn != 0 ) {
type = FileType_NoFile;
Expand Down