www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/04/08/17:23:32

Sender: nate AT cartsys DOT com
Message-ID: <370D1E26.F953128@cartsys.com>
Date: Thu, 08 Apr 1999 14:22:46 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.5 i586)
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: fflush question
References: <Pine DOT SUN DOT 3 DOT 91 DOT 990408112409 DOT 29868N-100000 AT is> <199904081555 DOT LAA13248 AT envy DOT delorie DOT com>
Reply-To: djgpp-workers AT delorie DOT com

DJ Delorie wrote:
> 
> > I agree, provided that many/most Unix systems indeed behave that way.
> > Could people please test this on the systems they have access to?
> 
> Linux doesn't need fsync().  This works as expected:

[snip]

Here's some weird results.  I used the same test program, slightly
modified:

test1.c: no fsync

#include <stdio.h>

main()
{
  FILE *a, *b;
  int i = 54321;

  a = fopen("foo1", "w");
  fprintf(a, "12345");
  fflush(a);

  b = fopen("foo1", "r");
  if (fscanf(b, "%d", &i) < 1)
	  printf("fscanf failed\n");
  else
	  printf("i=%d\n");
}


test2.c: with fsync

#include <stdio.h>
#include <unistd.h>
main()
{
  FILE *a, *b;
  int i = 54321;

  a = fopen("foo1", "w");
  fprintf(a, "12345");
  fflush(a);
  fsync(fileno(a));
  b = fopen("foo1", "r");
  fscanf(b, "%d", &i);
  if (fscanf(b, "%d", &i) < 1)
	  printf("fscanf failed\n");
  else
	  printf("i=%d\n");
}

And the results:

A Sun box:
$ uname -a
SunOS users 5.6 Generic sun4c sparc SUNW,Sun_4_50
$ ./test1
i=72704
$ ./test2
fscanf failed

An SGI:
Indigo:/disk7/WWW/eldredge/mine$ uname -a
IRIX Indigo 5.3 11091810 IP12 mips
Indigo:/disk7/WWW/eldredge/mine$ ./test1
i=1
Indigo:/disk7/WWW/eldredge/mine$ ./test2
fscanf failed

An strace of the SGI run reveals that a `read' is being done, and it
gets 12345.

So do these systems have serious bugs in scanf, or is there a subtle bug
in the test that I missed?

I don't think I'd base any of our decisions on them, in any case. 
Linux's model seems more like something to shoot for.
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


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