X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=internals%2F_PDCLIB_io.h;h=3561b211dcb16d87279ad5c2b6921836f3f4b867;hb=d1954049a406af2992113a783539aa5d86cfdfa8;hp=78e747c0edcc1df81a8184ca7a74372f4ef90a5a;hpb=3309ec3ad8a5db735eaa2de7f5dc6a331d8e7319;p=pdclib.old diff --git a/internals/_PDCLIB_io.h b/internals/_PDCLIB_io.h index 78e747c..3561b21 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; }; /******************************************************************************/ @@ -179,6 +179,9 @@ struct _PDCLIB_file _PDCLIB_size_t bufsize; /* Size of buffer */ _PDCLIB_size_t bufidx; /* Index of current position in buffer */ _PDCLIB_size_t bufend; /* Index of last pre-read character in buffer */ +#ifdef _PDCLIB_NEED_EOL_TRANSLATION + _PDCLIB_size_t bufnlexp; /* Current position of buffer newline expansion */ +#endif _PDCLIB_size_t ungetidx; /* Number of ungetc()'ed characters */ unsigned char * ungetbuf; /* ungetc() buffer */ unsigned int status; /* Status flags; see above */ @@ -206,21 +209,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; }