Implement stdio buffering #36

Merged
apio merged 7 commits from stdio-buffers into main 2023-07-22 09:39:02 +00:00
2 changed files with 24 additions and 2 deletions
Showing only changes of commit 085d2895e8 - Show all commits

View File

@ -132,8 +132,6 @@ extern "C"
/* Clear the error and end-of-file indicators in stream. */
void clearerr(FILE* stream);
void setbuf(FILE*, char*);
/* Write formatted output to a file. */
int fprintf(FILE* stream, const char* format, ...);
@ -191,6 +189,15 @@ extern "C"
/* Change a file's buffering mode and internal buffer. */
int setvbuf(FILE* stream, char* buf, int mode, size_t size);
/* Change a file's internal buffer. */
void setbuf(FILE* stream, char* buf);
/* Change a file's internal buffer. */
void setbuffer(FILE* stream, char* buf, size_t size);
/* Change a file's buffering mode to line buffered. */
void setlinebuf(FILE* stream);
#ifdef __cplusplus
}
#endif

View File

@ -729,4 +729,19 @@ extern "C"
return 0;
}
void setbuf(FILE* stream, char* buf)
{
setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
}
void setbuffer(FILE* stream, char* buf, size_t size)
{
setvbuf(stream, buf, buf ? _IOFBF : _IONBF, size);
}
void setlinebuf(FILE* stream)
{
setvbuf(stream, NULL, _IOLBF, 0);
}
}