 |
 |
relative path to FSRef
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2002
Location: Vancouver, Canada
Status:
Offline
|
|
i have an interesting question. When I feed a path that starts with ~/ to FSPathMakeRef() i get a -43 error....file not found.
The program I'm writing needs to access the current user's library folder so I cant think of any other way of doing this other than using the ~/library/ path. Does anyone have any suggestion on work arounds.
thanx
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Oct 2001
Location: Sweden
Status:
Offline
|
|
If you're using cocoa you can check out the NSString method stringByExpandingTildeInPath: or the Foundation function NSHomeDirectory()
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
Form a file URL for your path using either NSURL or CFURlRef (they're toll-free bridgable to one another, so you can just cast from one to the other). Use CFURLGetFSRef to get your FSRef. There is no step three.
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2002
Location: Vancouver, Canada
Status:
Offline
|
|
i dont see how using CFURL helps me. It wont aceept a path that starts with ~/. What I need is a carbon version of that cocoa tilde expansion function. Can anyone help?
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Code:
#include <CoreFoundation/CoreFoundation.h>
#include <unistd.h>
#include <pwd.h>
CFURLRef FDHomeDirectory( void );
CFURLRef FDHomeDirectoryForUserID( uid_t uid );
CFStringRef FDStringByReplacingTildeInPath( CFStringRef theString );
CFURLRef FDHomeDirectory( void )
{
return FDHomeDirectoryForUserID( geteuid() );
}
CFURLRef FDHomeDirectoryForUserID( uid_t uid )
{
struct passwd *pw = getpwuid( uid );
if (pw != NULL)
return CFURLCreateFromFileSystemRepresentation( NULL, pw->pw_dir, strlen(pw->pw_dir), true );
else
return NULL;
}
CFStringRef FDStringByReplacingTildeInPath( CFStringRef theString )
{
if ( CFStringHasPrefix( theString, CFSTR("~/") ) )
{
CFMutableStringRef mutableString = CFStringCreateMutableCopy( NULL, PATH_MAX, theString );
CFStringReplace( mutableString, CFRangeMake( 0, 1 ), CFURLCopyFileSystemPath( FDHomeDirectory(), kCFURLPOSIXPathStyle) );
return mutableString;
} else {
return theString;
}
}
int main (int argc, const char * argv[])
{
// insert code here...
CFStringRef string = CFSTR("~/Desktop");
CFShow( FDStringByReplacingTildeInPath( string ) );
return 0;
}
Fixing the leaks is left as an exercise for the reader. 
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |