Function to get a file's full pathname
|
|
Thread rating:  |
bg-greece - 18 Apr 2006 10:50 GMT Hi,
I need to run FSMakeFSSpec((short)0,0,"\pMyLib", &fss) in order to dynamically load a carbonised library in CW 8.3/Mac 10.4. It seems that I need to specify the full path of "MyLib" although it is placed in the current application folder. Since I do not want to specify the pathname inside FSMakeFSSpec, is there a way to get it through a function ? (btw. fopen("MyLib", "r") works perfectly)
Thanx Byron
sukhbir - 18 Apr 2006 16:24 GMT > Hi, > [quoted text clipped - 7 lines] > Thanx > Byron hi,
May be this will help you. Get working dir info using function PBGetWDInfoSync and then walk thru the hierarchy getting folder names & parent WD's
James W. Walker - 18 Apr 2006 17:23 GMT > I need to run FSMakeFSSpec((short)0,0,"\pMyLib", &fss) in order to > dynamically load a carbonised library in CW 8.3/Mac 10.4. It seems that I > need to specify the full path of "MyLib" although it is placed in the > current application folder. You can use GetProcessBundleLocation to find the FSRef of the application, then use FSGetCatalogInfo to find the volume reference number and parent directory ID. You can then use those numbers instead of zeros in the FSMakeFSSpec call.
bg-greece - 19 Apr 2006 10:13 GMT Since I am not much experienced in X, I would appreciate any sample code for doing that. After searching the newsgroups, I found the following:
OSStatus result=GetProcessBundleLocation(&PSN, &fsRef); result=FSGetCatalogInfo(&fsRef,kFSCatInfoNone,NULL,NULL,&theBundleSpec, &theParentRef);
I guess theBundleSpec.name will contain the name of the current directory? Howeer, the linker complained that it could not find GetProcessBundleLocation, what is the library I should include in my project?
James W. Walker - 19 Apr 2006 17:35 GMT > Since I am not much experienced in X, I would appreciate any sample code for > doing that. After searching the newsgroups, I found the following: [quoted text clipped - 4 lines] > > I guess theBundleSpec.name will contain the name of the current directory? No, you don't want the name of the current directory, especially considering that the name in the FSSpec will be mangled if the name is longer than 31 characters. The code would be something like
FSCatalogInfo catInfo; result = FSGetCatalogInfo( &fsRef, kFSCatInfoVolume | kFSCatInfoParentDirID, &catInfo, NULL, NULL, NULL );
> Howeer, the linker complained that it could not find > GetProcessBundleLocation, what is the library I should include in my > project? I don't recall if you said whether you were building CFM or Mach-O. If CFM, it's in CarbonLib; if Mach-O, Carbon.framework.
bg-greece - 21 Apr 2006 15:45 GMT >> Howeer, the linker complained that it could not find >> GetProcessBundleLocation, what is the library I should include in my >> project? > > I don't recall if you said whether you were building CFM or Mach-O. If > CFM, it's in CarbonLib; if Mach-O, Carbon.framework. My project is a Mach-O JNI library that wraps a carbonised shlb. I have included /Developer/SDK/MacOSX10.3.9.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/CarbonCore but the linker still complains about GetProcessBundleLocation (and not FSGetCatalogInfo). What is wrong?
Thanx.
James W. Walker - 21 Apr 2006 17:26 GMT > My project is a Mach-O JNI library that wraps a carbonised shlb. I have > included [quoted text clipped - 3 lines] > but the linker still complains about GetProcessBundleLocation (and not > FSGetCatalogInfo). What is wrong? Why don't you link to Carbon.framework rather than CarbonCore.framework? GetProcessBundleLocation is in HIServices.framework, but normally it's easier to use an "umbrella framework" like Carbon.framework.
bg-greece - 22 Apr 2006 13:51 GMT The directions you gave me made it possible to get the executable's directory (in my case the path of "java"), but not the current working directory. Is there a notion of "current working directory" in X? For the time being, system("pwd > cwd.txt") works OK, but I know it is not always the safer solution.
B.
Ben Artin - 22 Apr 2006 16:24 GMT > The directions you gave me made it possible to get the executable's > directory (in my case the path of "java"), but not the current working > directory. Is there a notion of "current working directory" in X? For the > time being, system("pwd > cwd.txt") works OK, but I know it is not always > the safer solution. There is, but if you are writing a GUI application, the working directory is not useful. Are you writing a GUI application or a command-line tool?
Ben
 Signature If this message helped you, consider buying an item from my wish list: <http://artins.org/ben/wishlist>
I changed my name: <http://periodic-kingdom.org/People/NameChange.php>
bg-greece - 23 Apr 2006 20:17 GMT I am writing a JNI shared library, and I need to know the current working directory. In fact, even system("pwd") is not perfectly right, because I get a "Users/byron/..." directory, but the FSSpec requires the volume (in my case "Macintosh HD") as well. Any ideas on (a) how to get the full current working directory pathname programmatically or (b) just the volume name, so I can add it to the result of UNIX's pwd.
James W. Walker - 23 Apr 2006 20:40 GMT > I am writing a JNI shared library, and I need to know the current working > directory. What do you need it for? There are actually two types of current working directory, one that applies to BSD functions (chdir, getcwd) and one for Carbon APIs (HSetVol, HGetVol).
bg-greece - 25 Apr 2006 08:41 GMT My Mach-O JNI library needs to dynamically load and run functions from a carbonised library in CW 8.3/Mac 10.4. This is why I run FSMakeFSSpec(0,0,"\pMyLib", &fss). Although the third argument needs to be fully specified, I don't want to "hardcode" it, since I don't know where the user of the library will place his application and my library. The only specification is that my library resides in the user's application folder, i.e. the current working directory.
Ben Artin - 25 Apr 2006 16:52 GMT > My Mach-O JNI library needs to dynamically load and run functions from a > carbonised library in CW 8.3/Mac 10.4. This is why I run [quoted text clipped - 3 lines] > specification is that my library resides in the user's application folder, > i.e. the current working directory. User's application folder has absolutely nothing to do with the current working directory.
Also, the Applications folder is the wrong place for your library. Either your library is a part of the application, in which case the library should be inside the application bundle, or your library is not a part of the application in which case it should go inside /Library/Application Support.
If your library is a part of the application, you would find the CFURLRef for it using CFBundleCopyAuxiliaryExecutableURL. That CFURLRef can then be converted to an FSSpec via CFURLGetFSRef and FSGetCatalogInfo.
If your library is not a part of the application, you would call FSFindFolder(kApplicationSupportFolderType, kLocalDomain) to find the Application Support folder, and then FSMakeFSRefUnicode to get the FSRef to your library.
hth,
Ben
 Signature If this message helped you, consider buying an item from my wish list: <http://artins.org/ben/wishlist>
I changed my name: <http://periodic-kingdom.org/People/NameChange.php>
|
|
|