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: 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