On Sun, 2009-03-01 at 02:17 +0100, Bruno Haible wrote: > Alan Hourihane wrote: > + fp->__pushback_bufp = 0; > + if (fp->__mode.__write) > + fp->__put_limit = fp->__buffer; > + fp->__bufp = fp->__get_limit; > > I don't think the last statement is right. The purpose of fpurge, on the read > side, is to empty the buffer, i.e. drop all read contents. I do agree that > at the end of this function, fp->__bufp == fp->__get_limit, should hold. > > Compare what is done on glibc systems. There, essentially > #define getc(fp) (fp->_IO_read_ptr < fp->_IO_read_end ? > *_fp->_IO_read_ptr++ : ...) > and fpurge does > fp->_IO_read_end = fp->_IO_read_ptr; > Consequently, on FreeMiNT, where getc is essentially > #define getc(fp) (fp->__bufp < fp->__get_limit ? *fp->__bufp++ : ...) > hence fpurge has to do > fp->__get_limit = fp->__bufp;
Quite right. Good catch. > I propose this instead in fpurge.c > > # elif defined __MINT__ /* Atari FreeMiNT */ > if (fp->__pushed_back) > { > fp->__bufp = fp->__pushback_bufp; > fp->__pushed_back = 0; > } > /* Preserve the current file position. */ > if (fp->__target != -1) > fp->__target += fp->__bufp - fp->__buffer; > fp->__bufp = fp->__buffer; > /* Nothing in the buffer, next getc is nontrivial. */ > fp->__get_limit = fp->__bufp; > /* Nothing in the buffer, next putc is nontrivial. */ > fp->__put_limit = fp->__buffer; > return 0; > > (The 'if (fp->__mode.__write)' in your variant is certainly redundant, right?) Yes. This works too. Alan.