X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Fgets.c;h=9dbc515f88cc8ae213c0be6c333160ba674d33b7;hb=393020b6e48719d27699dea6b29e53025bbd5123;hp=4aa45ff0117d2011ca102e79f16e08d5c3dc8900;hpb=cb1e312d4df84b4d73f4255af6b5be0c66407080;p=pdclib diff --git a/functions/stdio/gets.c b/functions/stdio/gets.c index 4aa45ff..9dbc515 100644 --- a/functions/stdio/gets.c +++ b/functions/stdio/gets.c @@ -10,9 +10,29 @@ #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 @@ -27,3 +47,4 @@ int main( void ) } #endif +