]> pd.if.org Git - pdclib/blobdiff - functions/stdio/fgetc.c
PDCLIB-18: Unify fgetc under _PDCLIB_getchars. Also unify gets under _PDCLIB_getchars...
[pdclib] / functions / stdio / fgetc.c
index ae7a8356685540e2582a1c5dcc7a9b350a530c18..61f52fdd4208a84a3000a1e937619d92191b85b7 100644 (file)
@@ -18,11 +18,12 @@ int fgetc_unlocked( struct _PDCLIB_file_t * stream )
     {
         return EOF;
     }
-    if ( stream->ungetidx > 0 )
-    {
-        return (unsigned char)stream->ungetbuf[ --(stream->ungetidx) ];
-    }
-    return (unsigned char)stream->buffer[stream->bufidx++];
+
+    char c;
+
+    size_t n = _PDCLIB_getchars( &c, 1, EOF, stream );
+
+    return n == 0 ? EOF : (unsigned char) c;
 }
 
 int fgetc( struct _PDCLIB_file_t * stream )