In article <macdev-C46EF6.10060514102003.DeleteThis@senator-bedfellow.mit.edu>,
Miro Jurisic <macdev.DeleteThis@meeroh.org> wrote:
> In article <spam-37012A.08344214102003.DeleteThis@news1-1.free.fr>,
> Paul Guyot <spam.DeleteThis@kallisys.com> wrote:
>
> > However, I wasn't aware of the CFBundle way. What does CFBundle has to do
> > with a command line tool? Could you please elaborate?
>
> Sorry, I misspoke, it was late. I meant GetProcessBundleLocation, not
> CFBundle.
That doesn't really answer the question of getting the path to a command
line tool, though. Unless I've missed something in my attempt below
(borrowed mostly from an Apple example):
ProcessSerialNumber psn = {0, kCurrentProcess};
FSRef processRef;
FSSpec fileSpec;
HFSUniStr255 *uniFileName;
FSCatalogInfo processInfo;
CFStringRef myPath;
uniFileName = MemAlloc(sizeof(HFSUniStr255));
GetProcessBundleLocation(&psn, &processRef);
FSGetCatalogInfo(&processRef, kFSCatInfoNodeFlags, &processInfo,
uniFileName, &fileSpec, NULL);
myPath = CFStringCreateWithCharacters(kCFAllocatorDefault,
uniFileName->unicode, uniFileName->length);
CFShow(myPath);
After compiling to "a.out", the last line always prints exactly that:
"a.out", with no information about the path to the executable.
I thought maybe the answer was in the FSCatalogInfo, but docs on that
structure indicate otherwise. Unless you're thinking of repeatedly
looking up parentDirID fields until one reaches the top of the file tree.
--
Tom "Tom" Harrington
Macaroni, Automated System Maintenance for Mac OS X.
Version 1.4: Best cleanup yet, gets files other tools miss.
See
http://www.atomicbird.com/