www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/02/12/06:01:21

Date: Mon, 12 Feb 2001 12:59:20 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Martin Stromberg <eplmst AT lu DOT erisoft DOT se>
cc: djgpp-workers AT delorie DOT com
Subject: Re: Bug000323
In-Reply-To: <200102120829.JAA14741@lws256.lu.erisoft.se>
Message-ID: <Pine.SUN.3.91.1010212125556.14499B-100000@is>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Mon, 12 Feb 2001, Martin Stromberg wrote:

> The question is: did you find another real bug in fflush()?

Yes, I think so.  See the source below: it never pays attention to the 
append flag.  So if you fseek somewhere, then fflush the stream, the data 
doesn't go to the correct place: the end of file.

int
fflush(FILE *f)
{
  char *base;
  int n, rn;

  if (f == NULL)
  {
    int e = errno;

    errno = 0;
    _fwalk((void (*)(FILE *))fflush);
    if (errno)
      return EOF;
    errno = e;
    return 0;
  }

  f->_flag &= ~_IOUNGETC;
  if ((f->_flag&(_IONBF|_IOWRT))==_IOWRT
      && (base = f->_base) != NULL
      && (rn = n = f->_ptr - base) > 0)
  {
    f->_ptr = base;
    f->_cnt = (f->_flag&(_IOLBF|_IONBF)) ? 0 : f->_bufsiz;
    do {
      /* If termios hooked this handle, call the termios hook.
	 We only do this with handles marked by putc and fwrite,
	 to prevent double conversion of NL to CR-LF and avoid
	 messing up the special termios conversions the user
	 might have requested for CR and NL.  */
      if ((f->_flag & _IOTERM) == 0
	  || __libc_write_termios_hook == NULL
	  || __libc_write_termios_hook(fileno(f), base, rn, &n) == 0)
	n = _write(fileno(f), base, rn);
      if (n <= 0) {
	f->_flag |= _IOERR;
	return EOF;
      }
      rn -= n;
      base += n;
    } while (rn > 0);
  }
  if (f->_flag & _IORW)
  {
    f->_cnt = 0;
    f->_flag &= ~(_IOWRT|_IOREAD);
    f->_ptr = f->_base;
  }
  return 0;
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019