• 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: Jakob Olesen <email@hidden>
  • Date: Mon, 24 Jul 2006 10:15:55 +0200


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
  • Follow-Ups:
    • Re: writing huge C-array to a file
      • From: PGM <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>)

  • Prev by Date: Re: Application upgrades itself?
  • Next by Date: Re: Finder-like color label menu item in Cocoa?
  • Previous by thread: Re: writing huge C-array to a file
  • Next by thread: Re: writing huge C-array to a file
  • Index(es):
    • Date
    • Thread