Sender: nate AT cartsys DOT com Message-ID: <370D1E26.F953128@cartsys.com> Date: Thu, 08 Apr 1999 14:22:46 -0700 From: Nate Eldredge 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: <199904081555 DOT LAA13248 AT envy DOT delorie DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 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 #include 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