fix(stdio): correct position tracking on mode switch and free owned buffers on close

This commit is contained in:
2026-09-04 23:42:03 -04:00
parent 22587bd545
commit 34408380f0
4 changed files with 137 additions and 8 deletions
+6 -3
View File
@@ -17,9 +17,11 @@
*
* Mode switching: reading while write data is pending flushes it first;
* writing while unread buffered data is pending seeks the kernel back to
* the logical position (discarding the unread data). F_PUSHED marks the
* single guaranteed ungetc pushback byte in `ungot`; a successful seek
* discards it.
* the logical position (discarding the unread data). F_WRITE doubles as
* the current-mode marker and is cleared by the read switch; F_RDWR
* records the write capability of update streams so the write switch can
* re-set F_WRITE. F_PUSHED marks the single guaranteed ungetc pushback
* byte in `ungot`; a successful seek discards it.
*
* The helper prototypes below are shared with the formatted-I/O todos
* (16: vfprintf, 17: vfscanf) so they operate on the same buffer state.
@@ -55,6 +57,7 @@ struct vlibc_FILE
#define F_OWNBUF 0x080 /* buf was allocated by the library */
#define F_HEAP 0x100 /* the FILE struct itself is heap-allocated */
#define F_PUSHED 0x200 /* ungot holds a pushed-back byte */
#define F_RDWR 0x400 /* update stream: reads and writes both enabled */
/* Flush pending write data; returns 0, or -1 with F_ERR set. */
hidden int