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:
@ -32,32 +32,27 @@ FILE *fmemopen(void *buf, size_t size, const char *mode) {
|
||||
FILE *f;
|
||||
char *p;
|
||||
unsigned flags;
|
||||
|
||||
if (size && size > 0x7ffff000) {
|
||||
einval();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(f = calloc(1, sizeof(FILE)))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!buf) {
|
||||
if (buf) {
|
||||
f->nofree = true;
|
||||
} else {
|
||||
if (!size) size = BUFSIZ;
|
||||
if (!(buf = calloc(1, size))) {
|
||||
free(f);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
f->nofree = true;
|
||||
}
|
||||
|
||||
f->fd = -1;
|
||||
f->buf = buf;
|
||||
f->size = size;
|
||||
f->end = size;
|
||||
f->size = size;
|
||||
f->iomode = fopenflags(mode);
|
||||
|
||||
if (f->iomode & O_APPEND) {
|
||||
if ((p = memchr(buf, '\0', size))) {
|
||||
f->beg = p - (char *)buf;
|
||||
@ -65,6 +60,5 @@ FILE *fmemopen(void *buf, size_t size, const char *mode) {
|
||||
f->beg = f->end;
|
||||
}
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user