Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit f12151c

Browse files
adeas31OpenModelica-Hudson
authored andcommitted
Make sure file is not modified before using the cache
Belonging to [master]: - #3017
1 parent b9d5e4a commit f12151c

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

Compiler/runtime/SimulationResults.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
#include <math.h>
1010
#include <gc.h>
1111
#include "omc_msvc.h" /* For INFINITY and NAN */
12-
#if !defined(__MINGW32__) && !defined(_MSC_VER)
1312
#include <time.h>
13+
#include <sys/types.h>
1414
#include <sys/stat.h>
15+
16+
#if defined(__MINGW32__) || defined(_MSC_VER)
17+
#define stat _stat
1518
#endif
1619

1720
#if defined(_MSC_VER)
@@ -31,9 +34,7 @@ const char *PlotFormatStr[] = {"Unknown","MATLAB4","PLT","CSV"};
3134
typedef struct {
3235
PlotFormat curFormat;
3336
char *curFileName;
34-
#if !defined(__MINGW32__) && !defined(_MSC_VER)
3537
time_t mtime;
36-
#endif
3738
ModelicaMatReader matReader;
3839
FILE *pltReader;
3940
struct csv_data *csvReader;
@@ -62,18 +63,13 @@ static PlotFormat SimulationResultsImpl__openFile(const char *filename, Simulati
6263
PlotFormat format;
6364
int len = strlen(filename);
6465
const char *msg[] = {"",""};
65-
#if !defined(__MINGW32__) && !defined(_MSC_VER)
6666
struct stat buf = {0} /* Zero this or valgrind complains */;
67-
#endif
67+
6868
if (simresglob->curFileName && 0==strcmp(filename,simresglob->curFileName)) {
69-
#if defined(__MINGW32__) || defined(_MSC_VER)
70-
return simresglob->curFormat; // Super cache :)
71-
#else
7269
/* Also check that the file was not modified */
7370
if (stat(filename, &buf)==0 && difftime(buf.st_mtime,simresglob->mtime)==0.0) {
7471
return simresglob->curFormat; // Super cache :)
7572
}
76-
#endif
7773
}
7874
// Start by closing the old file...
7975
SimulationResultsImpl__close(simresglob);

0 commit comments

Comments
 (0)