Couple notes on string encodings...

On Tue, Jun 2, 2009 at 4:50 PM, Jerry Krinock <[email protected]> wrote:
> + (NSData*)aliasRecordFromPath:(NSString*)path {
>    if ([path length] == 0) {
>        return nil ;
>    }
>
>    const char* pathC = [path UTF8String] ;

This should be [path fileSystemRepresentation]; Yes, this is UTF-8,
but IIRC it puts the string in a certain normalized form before UTF-8
encoding it.

> - (NSString*)pathFromAliasRecord {

[snip]

>        // Now try and resolve the alias
>        Boolean changed ;
>        OSErr osErr = FSResolveAlias(NULL,
>                                     (AliasHandle)handle,
>                                     &resolvedFSRef,
>                                     &changed) ;
>
>        if (osErr == noErr) {
>            // Alias was resolved.  Now get its path from resolvedFSRef
>            char pathC[4096] ;
>            OSStatus osStatus = FSRefMakePath(
>                                              &resolvedFSRef,
>                                              (UInt8*)pathC,
>                                              sizeof(pathC)
>            ) ;
>
>            if (osStatus != noErr) {
>                NSLog(@"Internal Error 959-2697.  OSStatus %i from
> FSResolveAlias", osStatus) ;
>                err = 1 ;
>            }
>            else {
>                path = [NSString stringWithCString:pathC] ;

I don't remember how stringWithCString tries to decode the string.
Maybe based on the default locale? Anyway, if you can stand to mandate
10.4, use +[NSString stringWithCString:encoding:]. Otherwise, it might
be best to wrap it in an NSData and then use -[NSString
initWithData:encoding:]. I know the docs recommend NSFileManager for
doing this conversion, but I seem to remember someone telling me that
NSFileManager is not thread-safe.
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to