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:
@ -16,20 +16,18 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
* Sets buffer on stdio stream.
|
||||
*
|
||||
* @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 is ignored if buf is NULL
|
||||
*/
|
||||
void setbuffer(FILE *f, char *buf, size_t size) {
|
||||
if (buf && f->buf != (unsigned char *)buf) {
|
||||
free_s(&f->buf);
|
||||
if (!size) size = BUFSIZ;
|
||||
f->buf = (unsigned char *)buf;
|
||||
}
|
||||
if (size) {
|
||||
f->size = size;
|
||||
}
|
||||
setvbuf(f, buf, buf ? _IOFBF : _IONBF, size);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user