RE: fread/fwrite/fflush bug
RE: fread/fwrite/fflush bug
- Subject: RE: fread/fwrite/fflush bug
- From: Norm Green <email@hidden>
- Date: Mon, 7 Jan 2008 09:49:19 -0800
Someone pointed out the fpurge() function.
Calling fpurge() on the reader before the 2nd read fixes the
problem.
Norm
Green
From: Norm Green [mailto:email@hidden]
Sent: Friday, January 04, 2008
1:37 PM
To: 'email@hidden'
Subject: fread/fwrite/fflush bug
I’ve found what I consider to be a stream IO bug.
The code below can be compiled with g++ to easily illustrate the problem.
Here’s what’s happening:
- Open a file for writing (using
fopen(…, “w”) ) and write some data to the file
- Flush the writer using fflush()
- Open a second stream to the
file for reading only using fopen(…., “r”)
- Read some bytes using fseek()
& fread() to confirm the reader can see the data written in step 1
- Have the writer update 1 byte
using fwrite()
- Flush the writer using fflush()
- Using the read stream, read the
byte written by the writer in step 5 using fseek() / fread()
- You will get the wrong answer
here. The read should return the byte written in step 5 but instead
returns the old value written in step 1.
Is this is a bug in Darwin?
Are there any work arounds?
Here’s my test case code. BTW, it passes on
Solaris.
Norm Green
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden