Unfortunately I can't do that as my class are wrappers around the ANSI file I/O calls such as fopen, etc. - so I have to match their prototypes.
________________________________ From: Adam R. Maxwell <amaxw...@mac.com> To: cocoa-dev Users <cocoa-dev@lists.apple.com> Sent: Wednesday, April 8, 2009 9:11:00 PM Subject: Re: Path from NSFileHandle? On Apr 8, 2009, at 8:54 PM, Michael Ash wrote: > On Wed, Apr 8, 2009 at 11:00 PM, Erg Consultant > <erg_consult...@yahoo.com> wrote: >> Is there a way to get the path of a file opened by an NSFileHandle from the >> file handle itself? I have a method that takes only an NSFileHandle to an >> open file but I don't know the file's path. > > Basically, you can't. An NSFileHandle is basically just a wrapper > around a UNIX file descriptor. A file descriptor might not even *have* > a path. For example, it might reference a pipe or network socket. If > it references a file, it might reference a file which has been > deleted. It could also reference a file with multiple hard links, > meaning that it would have *multiple* paths. > > It is possible to find this information if you *really* want to. The > fstat() call (use the -fileDescriptor method to get the file > descriptor to pass to it) will give you the device and inode number of > the file, if it has one. You can then search that device for a file > with that inode. But this will be slow, and again it might not even > exist. I recently noticed that you can use F_GETPATH with fcntl(2), but I've no idea what caveats are associated with it. It might be easier than messing with inodes directly, anyway? > Your best bet is to modify your code to pass the path to where it's needed. Definitely, or just figure out a way to use the NSFileHandle directly... --Adam _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com