Mail Archives: djgpp-workers/1999/04/08/17:23:32
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 -