bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [patch #6758] Add support for Atari FreeMiNT OS to fpurge


From: Bruno Haible
Subject: Re: [patch #6758] Add support for Atari FreeMiNT OS to fpurge
Date: Sun, 1 Mar 2009 02:17:52 +0100
User-agent: KMail/1.9.9

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;

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?)

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]