• 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: POSIX equiv to [nsBundle mainBundle] bundlePath]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: POSIX equiv to [nsBundle mainBundle] bundlePath]


  • Subject: Re: POSIX equiv to [nsBundle mainBundle] bundlePath]
  • From: James Quick <email@hidden>
  • Date: Thu, 24 Jul 2003 21:43:23 -0400

On Thursday, July 24, 2003, at 07:11 PM, tobias ford... wrote:

that's true. argv[0] gives it relative to the cwd. this is going to be a method in a library. using argv approach would require that I have some sort of initialize method that I must then require the user of the library to call very early in the program in an attempt to cache the data before someone else changed the cwd. Design wise, this locks me into something that is very similar in design to glut with it's glutInit method. This just makes using the lib too tricky to > use.

On Thursday, July 24, 2003, at 5:06PM, Chris Long wrote:

if you are running this from the shell your argv[0] will give you that string


On Friday, July 25, 2003, at 05:29 AM, tobias ford... wrote:

I'm needing to find a way to get the path to where the actual executable file resides using POSIX apis. For example:

foo is located at /usr/bin/foo

when I execute foo, I want it to print /usr/bin/foo no matter what directory I'm in.

something that is equivalent to [nsBundle mainBundle] bundlePath]

any suggestions? please cc me directly.

Jaguar and above define _NSGetExecutablePath in the System framework.

It's a snap if you will be linking Foundation already, but if you don't go that route
their is a straight C solution in sample code on Apple's site.

The solution they present is not portable to other unix flavors, but is the most efficient
way for OSX.

I am unaware of a portable approach which does not insist you be called first,
This one relies on exec stashing a copy of the executables path immediately
after the trailing NULL of envp.

http://developer.apple.com/samplecode/Sample_Code/Security/AuthSample/ getpath.c.htm

I don't recall if it this path contains symlinks, if it does, a call to realpath(3) will
normalize for you.
_______________________________________________
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.
  • Follow-Ups:
    • Re: POSIX equiv to [nsBundle mainBundle] bundlePath]
      • From: "tobias ford..." <email@hidden>
References: 
 >Re: POSIX equiv to [nsBundle mainBundle] bundlePath] (From: "tobias ford..." <email@hidden>)

  • Prev by Date: authorizenet AIM
  • Next by Date: Terminal App inside a Bundle App
  • Previous by thread: Re: POSIX equiv to [nsBundle mainBundle] bundlePath]
  • Next by thread: Re: POSIX equiv to [nsBundle mainBundle] bundlePath]
  • Index(es):
    • Date
    • Thread