From 4abab5ad6c8465a7528ccdd5f49367da05f78bbd Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Tue, 1 Oct 2024 15:47:05 +0200 Subject: Initial version --- src/stdio/ungetc.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/stdio/ungetc.c (limited to 'src/stdio/ungetc.c') diff --git a/src/stdio/ungetc.c b/src/stdio/ungetc.c new file mode 100644 index 0000000..bc629d4 --- /dev/null +++ b/src/stdio/ungetc.c @@ -0,0 +1,20 @@ +#include "stdio_impl.h" + +int ungetc(int c, FILE *f) +{ + if (c == EOF) return c; + + FLOCK(f); + + if (!f->rpos) __toread(f); + if (!f->rpos || f->rpos <= f->buf - UNGET) { + FUNLOCK(f); + return EOF; + } + + *--f->rpos = c; + f->flags &= ~F_EOF; + + FUNLOCK(f); + return (unsigned char)c; +} -- cgit v1.2.3