X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Fungetc.c;h=240dc401f507088138c5ff9bfd33d2bb164beaec;hb=d6f1494a4f38a212b29a13ee713885058dcf0fe7;hp=fdafc9de1054f34ca1e5b09c42ea06507ecf59e2;hpb=e5112b619d1aae8ffc439389cfcbd3b2b4bd2454;p=pdclib diff --git a/functions/stdio/ungetc.c b/functions/stdio/ungetc.c index fdafc9d..240dc40 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,21 @@ 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; }