Re: Converting OSX Path to a OS9 Path
Re: Converting OSX Path to a OS9 Path
- Subject: Re: Converting OSX Path to a OS9 Path
- From: Stéphane Sudre <email@hidden>
- Date: Tue, 7 Jan 2003 15:01:37 +0100
On mardi, janvier 7, 2003, at 11:38 AM, Flemming Bengtsson wrote:
Hi All,
How can you convert an OSX path string contained in a NSString to a OS9
Str255 path string ?
In theory, you can't since nothing can prevent a OSX path to be larger
than 255 bytes. Other issues involves the encoding of the file path
(UTF8 AFAIK).
If you're sure the file path is going to be smaller than 255 bytes, you
can do this:
/* Coded in Mail.app so it may contain bugs */
CFURLRef tURLRef;
NSString * tMacOSString;
const char * tCString;
Str255 myPascalString;
int tLength;
tURLRef=CFURLCreateWithFileSystemPath(kCFAllocatorDefault,(CFStringRef)
myPath,kCFURLPOSIXPathStyle,TRUE or FALSE);
tMacOSString =(NSString *)
CFURLCopyFileSystemPath(tURLRef,kCFURLHFSPathStyle);
tCString=[tMacOSString lossyCString]; // Say bye bye to encoding and
compatibility or use a compatible encoding converter
if (tCString!=NULL)
{
tLength=strlen(tCString);
if (tLength<256)
{
myPascalString[0]= tLength;
BlockMoveData(tCString, &myPascalString[1], tLength);
}
}
_______________________________________________
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.