• 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: writing huge C-array to a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: writing huge C-array to a file


  • Subject: Re: writing huge C-array to a file
  • From: PGM <email@hidden>
  • Date: Mon, 24 Jul 2006 09:55:54 -0400

Thanks! I first left out fclose, thinking that would be handled by [handle closeFile], but I noticed that only calling closeFile resulted in some EOF-error in the file so I used them both...

Patrick

On Jul 24, 2006, at 4:15, Jakob Olesen wrote:


On 24/07/2006, at 4.40, PGM wrote:

FILE *writing;
NSFileHandle *handle = [NSFileHandle fileHandleForUpdatingAtPath:fileName];
int descriptor = [handle fileDescriptor];
writing = fdopen(descriptor, "w");


//Now use fprintf for all the writing

fclose(writing);
[handle closeFile];

Small flaw: since your FILE* and NSFileHandle are sharing a file descriptor, you should only close it once. fclose() also flushes FILE* buffers, so keep that. Drop the [handle closeFile] call.


See man fdopen:

The fdopen() function associates a stream with the existing file descrip-
tor, fildes. The mode of the stream must be compatible with the mode of
the file descriptor. When the stream is closed via fclose(3), fildes is
closed also.


Worst case scenario: If something in your process opens a file between those two calls, you could close that file by accident.


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >writing huge C-array to a file (From: PGM <email@hidden>)
 >Re: writing huge C-array to a file (From: Bill Bumgarner <email@hidden>)
 >Re: writing huge C-array to a file (From: Steve Bird <email@hidden>)
 >Re: writing huge C-array to a file (From: Bill Bumgarner <email@hidden>)
 >Re: writing huge C-array to a file (From: PGM <email@hidden>)
 >Re: writing huge C-array to a file (From: Jakob Olesen <email@hidden>)

  • Prev by Date: Re: Best way to create string from an array of dictionaries?
  • Next by Date: Re: How to make a NSToolbarItem for view mode a la Finder?
  • Previous by thread: Re: writing huge C-array to a file
  • Next by thread: Re: Re: writing huge C-array to a file
  • Index(es):
    • Date
    • Thread