• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: fread/fwrite/fflush bug
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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:

 

  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:

This email sent to email@hidden

  • Prev by Date: fread/fwrite/fflush bug
  • Next by Date: IPv6 connection issues
  • Previous by thread: Re: fread/fwrite/fflush bug
  • Next by thread: Re: fread/fwrite/fflush bug
  • Index(es):
    • Date
    • Thread