30
30
*/
31
31
32
32
/* Changelog:
33
+ Oct. 20, 2024: by Thomas Beutlich
34
+ Removed legacy behaviour in ModelicaInternal_stat for
35
+ MSVC Visual Studio >= 2015 (ticket #4473)
36
+
33
37
Jan. 15, 2024: by Thomas Beutlich
34
38
Utilized ModelicaDuplicateString and
35
39
ModelicaDuplicateStringWithErrorReturn (ticket #3686)
@@ -279,7 +283,7 @@ void ModelicaInternal_setenv(_In_z_ const char* name,
279
283
#define HASH_NO_STDINT 1
280
284
#define HASH_NONFATAL_OOM 1
281
285
#include "uthash.h"
282
- #include "gconstructor .h"
286
+ #include "g2constructor .h"
283
287
284
288
#include <string.h>
285
289
#include <stdio.h>
@@ -402,10 +406,7 @@ static ModelicaFileType Internal_stat(_In_z_ const char* name) {
402
406
struct _stat fileInfo ;
403
407
int statReturn = _stat (name , & fileInfo );
404
408
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:" */
409
410
const char * firstSlash = strpbrk (name , "/\\" );
410
411
const char * firstColon = strchr (name , ':' );
411
412
const char c = (NULL != firstColon ) ? firstColon [1 ] : '\0' ;
@@ -419,6 +420,11 @@ static ModelicaFileType Internal_stat(_In_z_ const char* name) {
419
420
free (nameTmp );
420
421
}
421
422
}
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 */
422
428
else if (NULL != firstSlash && len > 1 &&
423
429
('/' == name [len - 1 ] || '\\' == name [len - 1 ])) {
424
430
char * nameTmp = (char * )malloc (len * (sizeof (char )));
@@ -429,6 +435,7 @@ static ModelicaFileType Internal_stat(_In_z_ const char* name) {
429
435
free (nameTmp );
430
436
}
431
437
}
438
+ #endif
432
439
}
433
440
if ( statReturn != 0 ) {
434
441
type = FileType_NoFile ;
@@ -774,16 +781,16 @@ typedef struct FileCache {
774
781
static FileCache * fileCache = NULL ;
775
782
#if defined(_POSIX_ ) && !defined(NO_MUTEX )
776
783
#include <pthread.h>
777
- #if defined(G_HAS_CONSTRUCTORS )
784
+ #if defined(G2_HAS_CONSTRUCTORS )
778
785
static 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 ) {
781
788
if (pthread_mutex_init (& m , NULL ) != 0 ) {
782
789
ModelicaError ("Initialization of mutex failed\n" );
783
790
}
784
791
}
785
- G_DEFINE_DESTRUCTOR ( destroyMutex )
786
- static void destroyMutex (void ) {
792
+ G2_DEFINE_DESTRUCTOR ( G2_FUNCNAME ( destroyMutex ) )
793
+ static void G2_FUNCNAME ( destroyMutex ) (void ) {
787
794
if (pthread_mutex_destroy (& m ) != 0 ) {
788
795
ModelicaError ("Destruction of mutex failed\n" );
789
796
}
@@ -793,24 +800,24 @@ static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
793
800
#endif
794
801
#define MUTEX_LOCK () pthread_mutex_lock(&m)
795
802
#define MUTEX_UNLOCK () pthread_mutex_unlock(&m)
796
- #elif defined(_WIN32 ) && defined(G_HAS_CONSTRUCTORS )
803
+ #elif defined(_WIN32 ) && defined(G2_HAS_CONSTRUCTORS )
797
804
#if !defined(WIN32_LEAN_AND_MEAN )
798
805
#define WIN32_LEAN_AND_MEAN
799
806
#endif
800
807
#include <windows.h>
801
808
static 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) )
804
811
#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 ) {
807
814
InitializeCriticalSection (& cs );
808
815
}
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) )
811
818
#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 ) {
814
821
DeleteCriticalSection (& cs );
815
822
}
816
823
#define MUTEX_LOCK () EnterCriticalSection(&cs)
0 commit comments