Make major improvements to stdio

Buffering now has optimal performance, bugs have been fixed, and some
missing apis have been introduced. This implementation is also now more
production worthy since it's less brittle now in terms of system errors.
That's going to help redbean since lua i/o is all based on stdio.

See #97
This commit is contained in:
Justine Tunney 2021-03-26 22:31:41 -07:00
parent 09bcfa23d5
commit da36e7e256
69 changed files with 1595 additions and 735 deletions

View file

@ -24,12 +24,19 @@
*
* @param mode may be _IOFBF, _IOLBF, or _IONBF
* @param buf may optionally be non-NULL to set the stream's underlying
* buffer, which the stream will own, but won't free
* @param size must be a two power if buf is provided
* buffer, which the stream will own, but won't free, otherwise the
* existing buffer is used
* @param size is ignored if buf is NULL
* @return 0 on success or -1 on error
*/
int setvbuf(FILE *f, char *buf, int mode, size_t size) {
setbuffer(f, buf, size);
if (buf) {
if (!size) size = BUFSIZ;
if (!f->nofree && f->buf != buf) free_s(&f->buf);
f->buf = buf;
f->size = size;
f->nofree = true;
}
f->bufmode = mode;
return 0;
}