X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Ffgets.c;h=fd893443b8679a27149c3f8f65d2e47ee0bd6b92;hb=b5b6c4a890795ea76f9b92b817b0a83c6bb4862c;hp=04510583ad29e82b46671106b81caac76399594e;hpb=84d648157e22cecc65902ecfdd4e3a1b88d5e53f;p=pdclib.old diff --git a/functions/stdio/fgets.c b/functions/stdio/fgets.c index 0451058..fd89344 100644 --- a/functions/stdio/fgets.c +++ b/functions/stdio/fgets.c @@ -9,10 +9,9 @@ #include #ifndef REGTEST +#include <_PDCLIB_io.h> -#include <_PDCLIB_glue.h> - -char * fgets_unlocked( char * _PDCLIB_restrict s, int size, struct _PDCLIB_file_t * _PDCLIB_restrict stream ) +char * _PDCLIB_fgets_unlocked( char * _PDCLIB_restrict s, int size, FILE * _PDCLIB_restrict stream ) { if ( size == 0 ) { @@ -28,30 +27,19 @@ 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; } char * fgets( char * _PDCLIB_restrict s, int size, - struct _PDCLIB_file_t * _PDCLIB_restrict stream ) + FILE * _PDCLIB_restrict stream ) { - flockfile( stream ); - char* r = fgets_unlocked( s, size, stream ); - funlockfile( stream ); + _PDCLIB_flockfile( stream ); + char* r = _PDCLIB_fgets_unlocked( s, size, stream ); + _PDCLIB_funlockfile( stream ); return r; }