mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
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:
parent
09bcfa23d5
commit
da36e7e256
69 changed files with 1595 additions and 735 deletions
|
@ -17,13 +17,20 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Pushes 𝑐 back to stream.
|
||||
* Pushes byte back to stream.
|
||||
*/
|
||||
int ungetc(int c, FILE *f) {
|
||||
uint32_t i;
|
||||
if (c == -1) return c;
|
||||
if (f->beg) f->buf[--f->beg] = c;
|
||||
return c;
|
||||
if (c == -1) return -1;
|
||||
if (f->beg) {
|
||||
f->buf[--f->beg] = c;
|
||||
} else if (f->end < f->size) {
|
||||
memmove(f->buf + 1, f->buf, f->end++);
|
||||
f->buf[0] = c;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
return c & 0xff;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue