X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Fungetc.c;h=dc5260b63a1a769bd37650e4be1fbad0c67f24e6;hb=d7154dc8cd1b7d41d0d956b7310e59d794f1a59f;hp=fdafc9de1054f34ca1e5b09c42ea06507ecf59e2;hpb=e5112b619d1aae8ffc439389cfcbd3b2b4bd2454;p=pdclib diff --git a/functions/stdio/ungetc.c b/functions/stdio/ungetc.c index fdafc9d..dc5260b 100644 --- a/functions/stdio/ungetc.c +++ b/functions/stdio/ungetc.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /* ungetc( int, FILE * ) This file is part of the Public Domain C Library (PDCLib). @@ -12,18 +10,22 @@ int ungetc( int c, struct _PDCLIB_file_t * stream ) { - /* TODO: Implement. */ - return 0; + if ( c == EOF || stream->ungetidx == _PDCLIB_UNGETCBUFSIZE ) + { + return -1; + } + return stream->ungetbuf[stream->ungetidx++] = (unsigned char) c; } #endif #ifdef TEST -#include <_PDCLIB_test.h> + +#include "_PDCLIB_test.h" int main( void ) { - TESTCASE( NO_TESTDRIVER ); + /* Testing covered by ftell.c */ return TEST_RESULTS; }