• 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: Path from NSFileHandle?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Path from NSFileHandle?


  • Subject: Re: Path from NSFileHandle?
  • From: Erg Consultant <email@hidden>
  • Date: Wed, 8 Apr 2009 21:55:12 -0700 (PDT)

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 <email@hidden>
To: cocoa-dev Users <email@hidden>
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
> <email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Path from NSFileHandle?
      • From: Michael Ash <email@hidden>
    • Re: Path from NSFileHandle?
      • From: Andrew Farmer <email@hidden>
References: 
 >Path from NSFileHandle? (From: Erg Consultant <email@hidden>)
 >Re: Path from NSFileHandle? (From: Michael Ash <email@hidden>)
 >Re: Path from NSFileHandle? (From: "Adam R. Maxwell" <email@hidden>)

  • Prev by Date: Re: Path from NSFileHandle?
  • Next by Date: Re: finder file size
  • Previous by thread: Re: Path from NSFileHandle?
  • Next by thread: Re: Path from NSFileHandle?
  • Index(es):
    • Date
    • Thread