]> pd.if.org Git - pdclib/blobdiff - functions/stdio/gets.c
Merged branch stdio_rewrite back into trunk.
[pdclib] / functions / stdio / gets.c
index 3529b0be466074c2550a3d68f3179c9156949d48..9dbc515f88cc8ae213c0be6c333160ba674d33b7 100644 (file)
@@ -7,13 +7,32 @@
 */
 
 #include <stdio.h>
-#include <limits.h>
 
 #ifndef REGTEST
 
+#define _PDCLIB_GLUE_H _PDCLIB_GLUE_H
+#include <_PDCLIB_glue.h>
+
 char * gets( char * s )
 {
-    return fgets( s, INT_MAX, stdin ); /* TODO: Replace with an unchecking call. */
+    if ( _PDCLIB_prepread( stdin ) == EOF )
+    {
+        return NULL;
+    }
+    char * dest = s;
+    while ( ( *dest = stdin->buffer[stdin->bufidx++] ) != '\n' )
+    {
+        if ( stdin->bufidx == stdin->bufend )
+        {
+            if ( _PDCLIB_fillbuffer( stdin ) == EOF )
+            {
+                return NULL;
+            }
+        }
+        ++dest;
+    }
+    *dest = '\n';
+    return s;
 }
 
 #endif
@@ -28,3 +47,4 @@ int main( void )
 }
 
 #endif
+