RE: Programatically determining @executable_path
RE: Programatically determining @executable_path
- Subject: RE: Programatically determining @executable_path
- From: "MacArthur, Ian (SELEX) (UK)" <email@hidden>
- Date: Mon, 30 Jan 2006 15:54:52 +0000
- Thread-topic: Xcode-users Digest, Vol 3, Issue 91
>
> Is there a way at runtime, to programatically determine what the
> value of @executable_path is for the current process?
Dunno if this is the answer to your question or not - but it works for me...
#include <sys/param.h>
#include <mach-o/dyld.h> /* _NSGetExecutablePath : must add -framework CoreFoundation to link line */
int status = -1;
char *given_path = malloc(MAXPATHLEN * 2);
if (!given_path) return status;
pathsize = MAXPATHLEN * 2;
result = _NSGetExecutablePath(given_path, &pathsize);
if (result == 0)
{ /* OK, we got something - now try and resolve the real path... */
if (realpath(given_path, pname) != NULL)
{
if ((access(pname, 0) == 0))
status = 0; /* exists, return OK */
}
}
free (given_path);
return status;
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden