Skip to content

Commit

Permalink
Port PDCLib's fflush
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterymath committed May 17, 2024
1 parent e6b2d7f commit 1b694c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions mos-platform/common/c/stdio-full.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,23 @@ int fclose(FILE *stream) {
return 0;
}

int fflush(FILE *stream) {
int rc = 0;

if (stream == NULL) {
/* TODO: Check what happens when fflush( NULL ) encounters write errors, in
* other libs */
for (stream = filelist; stream != NULL; stream = stream->next)
if (stream->status & FWRITE)
if (flush_buffer(stream) == EOF)
rc = EOF;
} else {
rc = flush_buffer(stream);
}

return rc;
}

FILE *fopen(const char *restrict filename, const char *restrict mode) {
unsigned int fmode = filemode(mode);

Expand Down
1 change: 1 addition & 0 deletions mos-platform/common/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ char *tmpnam(char *s);
// File access functions

int fclose(FILE *stream);
int fflush(FILE *stream);
FILE *fopen(const char *__restrict__ filename, const char *__restrict__ mode);

// Formated input/output functions
Expand Down

0 comments on commit 1b694c2

Please sign in to comment.