]> pd.if.org Git - pdclib/commitdiff
PDCLIB-18: Unify fgetc under _PDCLIB_getchars. Also unify gets under _PDCLIB_getchars...
authorOwen Shepherd <owen.shepherd@e43.eu>
Tue, 11 Dec 2012 02:00:22 +0000 (02:00 +0000)
committerOwen Shepherd <owen.shepherd@e43.eu>
Tue, 11 Dec 2012 02:00:22 +0000 (02:00 +0000)
functions/stdio/fgetc.c
functions/stdio/gets.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 )
index 9bf3a2694916d66a278a2a1e64135f1cd25a2427..3185396f7f2cdc0bd4e59574b6ed07a92702cd24 100644 (file)
@@ -10,6 +10,7 @@
 
 #ifndef REGTEST
 #include <_PDCLIB_glue.h>
+#include <stdint.h>
 
 char * gets( char * s )
 {
@@ -18,18 +19,15 @@ char * gets( char * s )
         return NULL;
     }
     char * dest = s;
-    while ( ( *dest = stdin->buffer[stdin->bufidx++] ) != '\n' )
-    {
-        ++dest;
-        if ( stdin->bufidx == stdin->bufend )
-        {
-            if ( _PDCLIB_fillbuffer( stdin ) == EOF )
-            {
-                break;
-            }
-        }
+    
+    dest += _PDCLIB_getchars( dest, SIZE_MAX, '\n', stdin );
+
+    if(*(dest - 1) == '\n') {
+        *(--dest) = '\0';
+    } else {
+        *dest = '\0';
     }
-    *dest = '\0';
+
     return ( dest == s ) ? NULL : s;
 }