Re: Unix FILE* and NSFileHandle
Re: Unix FILE* and NSFileHandle
- Subject: Re: Unix FILE* and NSFileHandle
- From: Jason Moore <email@hidden>
- Date: Sun, 31 Mar 2002 18:30:10 -0600
Nat!,
Thanks for the help! One more question:
How do you convert from a NSFileHandle to a FILE* structure?
I have a NSFileHande instance that i'd like to pass to a library
function that needs a FILE* as the parameter.
Thanks in advance.
Jason
On Friday, March 29, 2002, at 02:19 PM, Nat! wrote:
Am Freitag den, 29. Mdrz 2002, um 20:22, schrieb Jason Moore:
Greetings fellow Cocoa nuts.. :)
Does anyone out there know if Cocoa is capable of converting between
standard unix FILE* structures and NSFileHandle? Anyone know how to do
that if cocoa can't?
Ahem, lecturing here, FILE is a stdlib C structure, whereas "int" is
the UNIX file handle. Thusly things resolve neatly into:
FILE *fp;
NSFileHandle *p;
fp = fopen( "foo", "r");
p = [[[NSFileHandle alloc] initWithFileDescriptor:fileno( fp)
closeOnDealloc:YES] autorelease];
Be careful not to read from fp, because stdio caches.
Easier though:
fd = open( "foo", 0);
p = [[[NSFileHandle alloc] initWithFileDescriptor:fd
closeOnDealloc:YES] autorelease];
I don't personally use NSFileHandles at all :)
Cheers
Nat!
------------------------------------------------------
Some people drink deep from the fountains of life, and
some just gargle. -- DLR
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.