X-Git-Url: https://pd.if.org/git/?p=pdclib.old;a=blobdiff_plain;f=internals%2F_PDCLIB_io.h;fp=internals%2F_PDCLIB_io.h;h=2ece56ce194b4ea3b0387f099770d5ef0a001142;hp=829bb4586ed66781c2b2aca73f88f934651678a5;hb=d9be4032fa26b8714ec95e1da2c0928f9c79dd44;hpb=0ea57627a2a2422a349a0c8c840d09eac084a8ac diff --git a/internals/_PDCLIB_io.h b/internals/_PDCLIB_io.h index 829bb45..2ece56c 100644 --- a/internals/_PDCLIB_io.h +++ b/internals/_PDCLIB_io.h @@ -151,5 +151,40 @@ struct _PDCLIB_file_t struct _PDCLIB_file_t * next; /* Pointer to next struct (internal) */ }; +static inline _PDCLIB_size_t _PDCLIB_getchars( char * out, _PDCLIB_size_t n, + int stopchar, + struct _PDCLIB_file_t * stream ) +{ + _PDCLIB_size_t i = 0; + int c; + while ( stream->ungetidx > 0 && i != n ) + { + c = (unsigned char) + ( out[ i++ ] = stream->ungetbuf[ --(stream->ungetidx) ] ); + if( c == stopchar ) + return i; + } + + while ( i != n ) + { + while ( stream->bufidx != stream->bufend && i != n) + { + c = (unsigned char) + ( out[ i++ ] = stream->buffer[ stream->bufidx++ ] ); + if( c == stopchar ) + return i; + } + + if ( stream->bufidx == stream->bufend ) + { + if( _PDCLIB_fillbuffer( stream ) == -1 ) + { + return i; + } + } + } + + return i; +} #endif