Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: fread/fwrite/fflush bug



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:

 

  1. Open a file for writing (using fopen(…, “w”) ) and write some data to the file
  2. Flush the writer using fflush()
  3. Open a second stream to the file for reading only using fopen(…., “r”)
  4. Read some bytes using fseek() & fread() to confirm the reader can see the data written in step 1
  5. Have the writer update 1 byte using fwrite()
  6. Flush the writer using fflush()
  7. Using the read stream, read the byte written by the writer in step 5 using fseek() / fread()
  8. 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:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.