X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Fgets.c;h=9dbc515f88cc8ae213c0be6c333160ba674d33b7;hb=0d54a75af25ca44411e7c4190cc2a93a390e61a2;hp=27575223581ef8fa1f8ce1b9e52740ec21cc0f5f;hpb=42e018009a78cdddd97fd18d2b6bb02d8e0fe16e;p=pdclib.old diff --git a/functions/stdio/gets.c b/functions/stdio/gets.c index 2757522..9dbc515 100644 --- a/functions/stdio/gets.c +++ b/functions/stdio/gets.c @@ -7,13 +7,32 @@ */ #include -#include #ifndef REGTEST +#define _PDCLIB_GLUE_H _PDCLIB_GLUE_H +#include <_PDCLIB_glue.h> + char * gets( char * s ) { - return fgets( s, SIZE_MAX, stdin ); + 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 +