Re: writing huge C-array to a file
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