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=2df3ff5ca6dd1b31927a32abd8097938acef24d6;hp=78e747c0edcc1df81a8184ca7a74372f4ef90a5a;hb=cd6cfe0f578c4f744ddc9a342243aff6b42f8027;hpb=29bef599b18dd551f96520ae051994706805157c diff --git a/internals/_PDCLIB_io.h b/internals/_PDCLIB_io.h index 78e747c..2df3ff5 100644 --- a/internals/_PDCLIB_io.h +++ b/internals/_PDCLIB_io.h @@ -14,7 +14,7 @@ */ #define _PDCLIB_FREAD 8u #define _PDCLIB_FWRITE 16u -#define _PDCLIB_FAPPEND 32u +#define _PDCLIB_FAPPEND 32u #define _PDCLIB_FRW 64u #define _PDCLIB_FBIN 128u @@ -41,7 +41,7 @@ union _PDCLIB_fd #endif void * pointer; _PDCLIB_uintptr_t uval; - _PDCLIB_intptr_t sval; + _PDCLIB_intptr_t sval; }; /******************************************************************************/ @@ -206,21 +206,43 @@ static inline _PDCLIB_size_t _PDCLIB_getchars( char * out, _PDCLIB_size_t n, { while ( stream->bufidx != stream->bufend && i != n) { - c = (unsigned char) - ( out[ i++ ] = stream->buffer[ stream->bufidx++ ] ); + c = (unsigned char) stream->buffer[ stream->bufidx++ ]; +#ifdef _PDCLIB_NEED_EOL_TRANSLATION + if ( !( stream->status & _PDCLIB_FBIN ) && c == '\r' ) + { + if ( stream->bufidx == stream->bufend ) + break; + + if ( stream->buffer[ stream->bufidx ] == '\n' ) + { + c = '\n'; + stream->bufidx++; + } + } +#endif + out[ i++ ] = c; + if( c == stopchar ) return i; } - if ( stream->bufidx == stream->bufend ) + if ( i != n ) { if( _PDCLIB_fillbuffer( stream ) == -1 ) { - return i; + break; } } } +#ifdef _PDCLIB_NEED_EOL_TRANSLATION + if ( i != n && stream->bufidx != stream->bufend ) + { + // we must have EOF'd immediately after a \r + out[ i++ ] = stream->buffer[ stream->bufidx++ ]; + } +#endif + return i; }