diff options
Diffstat (limited to 'ecomp-c/libc-freestanding.c')
-rw-r--r-- | ecomp-c/libc-freestanding.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/ecomp-c/libc-freestanding.c b/ecomp-c/libc-freestanding.c index ca41ae7..f37aa83 100644 --- a/ecomp-c/libc-freestanding.c +++ b/ecomp-c/libc-freestanding.c @@ -399,9 +399,10 @@ typedef struct { int readpos; int size; char buf[INTERNAL_STDIO_BUFSIZE]; + int pushback; } FILE; -static FILE fds[3] = { { STDIN_FILENO, 0, 0, "" }, { STDOUT_FILENO, 0, 0, "" }, { STDERR_FILENO, 0, 0, "" } }; +static FILE fds[3] = { { STDIN_FILENO, 0, 0, "", 0 }, { STDOUT_FILENO, 0, 0, "", 0 }, { STDERR_FILENO, 0, 0, "", 0 } }; FILE *stdin = &fds[0]; FILE *stdout = &fds[1]; @@ -586,6 +587,12 @@ int fgetc( FILE *stream ) { int c; + if( stream->pushback != 0 ) { + c = stream->pushback; + stream->pushback = 0; + return c; + } + if( stream->size == 0 ) { int n = read_string( stream->fileno, stream->buf, INTERNAL_STDIO_BUFSIZE ); if( n < 0 ) { @@ -606,6 +613,13 @@ int fgetc( FILE *stream ) return c; } +int ungetc( int c, FILE *stream ) +{ + stream->pushback = c; + + return c; +} + int getchar( void ) { return fgetc( stdin ); |