Skip to content

Commit cab1614

Browse files
committed
- Added System.appendFile to bootstrapped runtime.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10716 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 35c2895 commit cab1614

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

Compiler/runtime/System_omc.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ extern void System_writeFile(const char* filename, const char* data)
4444
MMC_THROW();
4545
}
4646

47+
extern void System_appendFile(const char *filename, const char *data)
48+
{
49+
if (SystemImpl__appendFile(filename, data))
50+
MMC_THROW();
51+
}
52+
4753
extern int System_removeFile(const char* filename)
4854
{
4955
return SystemImpl__removeFile(filename);

Compiler/runtime/System_rml.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -480,25 +480,10 @@ RML_END_LABEL
480480

481481
RML_BEGIN_LABEL(System__appendFile)
482482
{
483-
const char* data = RML_STRINGDATA(rmlA1);
484483
const char* filename = RML_STRINGDATA(rmlA0);
485-
FILE * file=NULL;
486-
file = fopen(filename, "a");
487-
if (file == NULL) {
488-
const char *c_tokens[1]={filename};
489-
c_add_message(21, /* WRITING_FILE_ERROR */
490-
ErrorType_scripting, ErrorLevel_error,
491-
"Error appending to file %s.",
492-
c_tokens,
493-
1);
484+
const char* data = RML_STRINGDATA(rmlA1);
485+
if (SystemImpl__appendFile(filename, data))
494486
RML_TAILCALLK(rmlFC);
495-
}
496-
/* adrpo changed 2006-10-06
497-
* fprintf(file,"%s",data);
498-
*/
499-
fwrite(RML_STRINGDATA(rmlA1), RML_HDRSTRLEN(RML_GETHDR(rmlA1)), 1, file);
500-
fflush(file);
501-
fclose(file);
502487
RML_TAILCALLK(rmlSC);
503488
}
504489
RML_END_LABEL

Compiler/runtime/systemimpl.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,28 @@ int SystemImpl__writeFile(const char* filename, const char* data)
396396
return 0;
397397
}
398398

399+
/* returns 0 on success */
400+
int SystemImpl__appendFile(const char* filename, const char *data)
401+
{
402+
FILE *file = NULL;
403+
file = fopen(filename, "a");
404+
405+
if(file == NULL) {
406+
const char *c_tokens[1] = {filename};
407+
c_add_message(21, /* WRITING_FILE_ERROR */
408+
ErrorType_scripting, ErrorLevel_error,
409+
"Error appending to file %s.",
410+
c_tokens,
411+
1);
412+
return 1;
413+
}
414+
415+
fwrite(data, strlen(data), 1, file);
416+
fflush(file);
417+
fclose(file);
418+
return 0;
419+
}
420+
399421
static int str_contain_char( const char* chars, const char chr)
400422
{
401423
int length_of_chars = strlen(chars);

0 commit comments

Comments
 (0)