mbox series

[0/3] Guarantee first pushback in ungetc and ungetwc

Message ID 20241108171450.411932-1-siddhesh@sourceware.org
Headers show
Series Guarantee first pushback in ungetc and ungetwc | expand

Message

Siddhesh Poyarekar Nov. 8, 2024, 5:14 p.m. UTC
The C standard requires the first pushback after read operations to
succeed for ungetc and ungetwc.  Use a single-char buffer in the FILE
struct to guarantee this, so that the calls are not subject to a malloc
failure.

Tested on x86_64.

Siddhesh Poyarekar (3):
  libio: make _IO_least_marker static
  ungetc: Guarantee single char pushback
  ungetwc: Guarantee single char pushback

 libio/Makefile                  |  1 +
 libio/bits/types/struct_FILE.h  |  3 +-
 libio/fileops.c                 | 21 +++-----
 libio/genops.c                  | 35 ++++++------
 libio/libio.h                   |  1 +
 libio/tst-ungetwc-nomem.c       | 94 +++++++++++++++++++++++++++++++++
 libio/wfileops.c                | 28 +++-------
 libio/wgenops.c                 | 29 +++++-----
 stdio-common/Makefile           |  1 +
 stdio-common/tst-ungetc-nomem.c | 94 +++++++++++++++++++++++++++++++++
 10 files changed, 240 insertions(+), 67 deletions(-)
 create mode 100644 libio/tst-ungetwc-nomem.c
 create mode 100644 stdio-common/tst-ungetc-nomem.c