3030*/
3131
3232/* Changelog:
33+ Oct. 20, 2024: by Thomas Beutlich
34+ Removed legacy behaviour in ModelicaInternal_stat for
35+ MSVC Visual Studio >= 2015 (ticket #4473)
36+
3337 Jan. 15, 2024: by Thomas Beutlich
3438 Utilized ModelicaDuplicateString and
3539 ModelicaDuplicateStringWithErrorReturn (ticket #3686)
@@ -279,7 +283,7 @@ void ModelicaInternal_setenv(_In_z_ const char* name,
279283#define HASH_NO_STDINT 1
280284#define HASH_NONFATAL_OOM 1
281285#include "uthash.h"
282- #include "gconstructor .h"
286+ #include "g2constructor .h"
283287
284288#include <string.h>
285289#include <stdio.h>
@@ -402,10 +406,7 @@ static ModelicaFileType Internal_stat(_In_z_ const char* name) {
402406 struct _stat fileInfo ;
403407 int statReturn = _stat (name , & fileInfo );
404408 if (0 != statReturn ) {
405- /* For some reason _stat requires "a:\" and "a:\test1" but fails
406- * on "a:" and "a:\test1\", respectively. It could be handled in the
407- * Modelica code, but seems better to have it here.
408- */
409+ /* _stat requires "a:\" instead of "a:" */
409410 const char * firstSlash = strpbrk (name , "/\\" );
410411 const char * firstColon = strchr (name , ':' );
411412 const char c = (NULL != firstColon ) ? firstColon [1 ] : '\0' ;
@@ -419,6 +420,11 @@ static ModelicaFileType Internal_stat(_In_z_ const char* name) {
419420 free (nameTmp );
420421 }
421422 }
423+ #if defined(_MSC_VER ) && _MSC_VER >= 1900
424+ /* _stat accepts both "a:\dir" and "a:\dir\" */
425+ #else
426+ /* _stat requires "a:\dir" instead of "a:\dir\" */
427+ /* required for VS 2013 and earlier */
422428 else if (NULL != firstSlash && len > 1 &&
423429 ('/' == name [len - 1 ] || '\\' == name [len - 1 ])) {
424430 char * nameTmp = (char * )malloc (len * (sizeof (char )));
@@ -429,6 +435,7 @@ static ModelicaFileType Internal_stat(_In_z_ const char* name) {
429435 free (nameTmp );
430436 }
431437 }
438+ #endif
432439 }
433440 if ( statReturn != 0 ) {
434441 type = FileType_NoFile ;
@@ -774,16 +781,16 @@ typedef struct FileCache {
774781static FileCache * fileCache = NULL ;
775782#if defined(_POSIX_ ) && !defined(NO_MUTEX )
776783#include <pthread.h>
777- #if defined(G_HAS_CONSTRUCTORS )
784+ #if defined(G2_HAS_CONSTRUCTORS )
778785static pthread_mutex_t m ;
779- G_DEFINE_CONSTRUCTOR ( initializeMutex )
780- static void initializeMutex (void ) {
786+ G2_DEFINE_CONSTRUCTOR ( G2_FUNCNAME ( initializeMutex ) )
787+ static void G2_FUNCNAME ( initializeMutex ) (void ) {
781788 if (pthread_mutex_init (& m , NULL ) != 0 ) {
782789 ModelicaError ("Initialization of mutex failed\n" );
783790 }
784791}
785- G_DEFINE_DESTRUCTOR ( destroyMutex )
786- static void destroyMutex (void ) {
792+ G2_DEFINE_DESTRUCTOR ( G2_FUNCNAME ( destroyMutex ) )
793+ static void G2_FUNCNAME ( destroyMutex ) (void ) {
787794 if (pthread_mutex_destroy (& m ) != 0 ) {
788795 ModelicaError ("Destruction of mutex failed\n" );
789796 }
@@ -793,24 +800,24 @@ static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
793800#endif
794801#define MUTEX_LOCK () pthread_mutex_lock(&m)
795802#define MUTEX_UNLOCK () pthread_mutex_unlock(&m)
796- #elif defined(_WIN32 ) && defined(G_HAS_CONSTRUCTORS )
803+ #elif defined(_WIN32 ) && defined(G2_HAS_CONSTRUCTORS )
797804#if !defined(WIN32_LEAN_AND_MEAN )
798805#define WIN32_LEAN_AND_MEAN
799806#endif
800807#include <windows.h>
801808static CRITICAL_SECTION cs ;
802- #ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
803- #pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS( ModelicaInternal_initializeCS)
809+ #ifdef G2_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
810+ #pragma G2_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(G2_FUNCNAME( ModelicaInternal_initializeCS) )
804811#endif
805- G_DEFINE_CONSTRUCTOR ( ModelicaInternal_initializeCS )
806- static void ModelicaInternal_initializeCS (void ) {
812+ G2_DEFINE_CONSTRUCTOR ( G2_FUNCNAME ( ModelicaInternal_initializeCS ) )
813+ static void G2_FUNCNAME ( ModelicaInternal_initializeCS ) (void ) {
807814 InitializeCriticalSection (& cs );
808815}
809- #ifdef G_DEFINE_DESTRUCTOR_NEEDS_PRAGMA
810- #pragma G_DEFINE_DESTRUCTOR_PRAGMA_ARGS( ModelicaInternal_deleteCS)
816+ #ifdef G2_DEFINE_DESTRUCTOR_NEEDS_PRAGMA
817+ #pragma G2_DEFINE_DESTRUCTOR_PRAGMA_ARGS(G2_FUNCNAME( ModelicaInternal_deleteCS) )
811818#endif
812- G_DEFINE_DESTRUCTOR ( ModelicaInternal_deleteCS )
813- static void ModelicaInternal_deleteCS (void ) {
819+ G2_DEFINE_DESTRUCTOR ( G2_FUNCNAME ( ModelicaInternal_deleteCS ) )
820+ static void G2_FUNCNAME ( ModelicaInternal_deleteCS ) (void ) {
814821 DeleteCriticalSection (& cs );
815822}
816823#define MUTEX_LOCK () EnterCriticalSection(&cs)
0 commit comments