www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/04/06/05:24:50

Message-ID: <B0FEA00E82A7D1118BFB00A0CC990278213234@ARGON>
From: Michel de Ruiter <Michel AT smr DOT nl>
To: "'DJGPP workers'" <djgpp-workers AT delorie DOT com>
Subject: fflush question
Date: Tue, 6 Apr 1999 11:26:21 +0200
X-Mailer: Internet Mail Service (5.5.2448.0)
Reply-To: djgpp-workers AT delorie DOT com

Hi, all.

The following program does not do what I (and Autoconf) expected:

#include <stdio.h>
int main(void)
{
  FILE *fpw, *fpr;
  char array[7];
  fpw = fopen("conftes0", "w");
  fwrite("FOOBAR", 1, 7, fpw);
  fflush(fpw);
  /*fsync(fileno(fpw));*/
  fpr = fopen("conftes0", "r");
  return fread(array, 1, 7, fpr);
}

This returns 0, unless the fsync is turned on. Is this allowed and
intended this way? The ANSI C9x draft (January 18, 7.19.5.2, page 306)
says about fflush's functionality in this case:

     ... the fflush function causes any unwritten data ... to be
     delivered to the host environment to be written to the file ...

I cannot find anything about one file being open as two streams (input
and output) simultaneously, except (7.19.3, page 301):

    Whether the same file can be simultaneously open multiple times is
    ... implementation-defined.


Oh, now we are at it, ANSI C9x (Annex J.2, page 557) says trying to
fflush an input stream causes undefined behaviour, "with or without
the issuance of a diagnostic message". Maybe we should consider
generating some warning?


And another thing that I noticed while at this, fflush.txh says:

    Note that @code{fflush} has no effect for streams opened for
    reading only.

But fflush.c nevertheless does:

    f->_flag &= ~_IOUNGETC;

I assume this *can* have effect on an input stream. Which behaviour is
intented?

--
*Groeten, Michel* _http://www.cs.vu.nl/~mdruiter_
   ____________ 
   \  /====\  /   "You know, Beavis, you need things that suck,
    \/      \/     to have things that are cool", Butt-Head.

- Raw text -


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