X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstdio%2Ffgets.c;h=6fbc2ef7961509b7e0c93aeae610d001f1a84f90;hp=04510583ad29e82b46671106b81caac76399594e;hb=e6d28b5afddd8b3e3564af2264aa8b705e711b67;hpb=7f9e4ed1a81518df0aed2dfe2b18ee12dbadfa79 diff --git a/functions/stdio/fgets.c b/functions/stdio/fgets.c index 0451058..6fbc2ef 100644 --- a/functions/stdio/fgets.c +++ b/functions/stdio/fgets.c @@ -28,20 +28,9 @@ char * fgets_unlocked( char * _PDCLIB_restrict s, int size, struct _PDCLIB_file_ return NULL; } char * dest = s; - while ( ( ( *dest++ = stream->buffer[stream->bufidx++] ) != '\n' ) && --size > 0 ) - { - if ( stream->bufidx == stream->bufend ) - { - if ( _PDCLIB_fillbuffer( stream ) == EOF ) - { - /* In case of error / EOF before a character is read, this - will lead to a \0 be written anyway. Since the results - are "indeterminate" by definition, this does not hurt. - */ - break; - } - } - } + + dest += _PDCLIB_getchars( dest, size - 1, '\n', stream ); + *dest = '\0'; return ( dest == s ) ? NULL : s; }