1143598Sscottl#include "stdio_impl.h"
2143598Sscottl
3143598Sscottlint ungetc(int c, FILE *f)
4143598Sscottl{
5143598Sscottl	if (c == EOF) return c;
6143598Sscottl
7143598Sscottl	FLOCK(f);
8143598Sscottl
9143598Sscottl	if (!f->rpos) __toread(f);
10143598Sscottl	if (!f->rpos || f->rpos <= f->buf - UNGET) {
11143598Sscottl		FUNLOCK(f);
12143598Sscottl		return EOF;
13143598Sscottl	}
14143598Sscottl
15143598Sscottl	*--f->rpos = c;
16143598Sscottl	f->flags &= ~F_EOF;
17143598Sscottl
18143598Sscottl	FUNLOCK(f);
19143598Sscottl	return c;
20143598Sscottl}
21143598Sscottl