summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/stdio/ungetc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc-top-half/musl/src/stdio/ungetc.c')
-rw-r--r--libc-top-half/musl/src/stdio/ungetc.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/stdio/ungetc.c b/libc-top-half/musl/src/stdio/ungetc.c
new file mode 100644
index 0000000..bc629d4
--- /dev/null
+++ b/libc-top-half/musl/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;
+}