Skip navigation.
 
mlNot so long filenames
FROM : Gerriet M. Denkmann
DATE : Tue Oct 14 17:28:04 2008

HFS+ and Finder can use filenames which use in Utf-16 up to 255 shorts.

But in the program below there seems to exist some other limit (at 
least on 10.4.11 Tiger).
Where is this documented?
Or what am I doing wong?


#import <Cocoa/Cocoa.h>

int main (int argc, const char * argv[])
{
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   
  NSData *data = [ @"Some Data" dataUsingEncoding: 
NSUTF8StringEncoding ];
  NSFileWrapper *aWrapper = [ [ NSFileWrapper alloc ] 
initRegularFileWithContents: data ];
   NSString *f2 = [ NSString stringWithUTF8String:     //    64 * DESERET 
CAPITAL LETTER LONG I
                                           "𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀
𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀
𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀
𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀"// 64
                   ];
  [ aWrapper setPreferredFilename: f2 ];
   
  NSLog(@"%s Filewrapper has preferred filename with %u shorts in 
Utf16; "
           "Utf8 of fileSystemRepresentation has %u bytes",
           __FUNCTION__, [ f2 length], strlen([f2 fileSystemRepresentation]));

  NSTextAttachment *attachment = [ [ NSTextAttachment alloc ] 
initWithFileWrapper: aWrapper ];
  NSAttributedString *textStorage = [ NSMutableAttributedString 
attributedStringWithAttachment: attachment ];

  NSRange all = NSMakeRange( 0, [ textStorage length ] );
  NSFileWrapper *fw = [ textStorage     RTFDFileWrapperFromRange: all 
documentAttributes: nil ];
   if ( fw == nil )    //    error
   {
       NSLog(@"%s Error: RTFDFileWrapperFromRange",__FUNCTION__);
       return 1;
   };
   
   NSString *path = @"/tmp/a.rtfd";
   BOOL ok = [ fw writeToFile: path atomically: NO updateFilenames: NO ];
   if ( !ok )    //    error
   {
       //    we come here if strlen([f2 fileSystemRepresentation]) > 255
       
       NSLog(@"%s Error: writeToFile",__FUNCTION__);
       return 2;
   };

   NSLog(@"%s wrote rtfd wrapper %@",__FUNCTION__, path);
   
    [pool release];
    return 0;
}

Result:

... Filewrapper has preferred filename with 128 shorts in Utf16; Utf8 
of fileSystemRepresentation has 256 bytes
... Error: writeToFile
Filename has exited with status 2.

Related mailsAuthorDate
mlNot so long filenames Gerriet M. Denkman… Oct 14, 17:28
mlRe: Not so long filenames Jason Coco Oct 14, 18:07
mlRe: Not so long filenames Gerriet M. Denkman… Oct 14, 22:00
mlRe: Not so long filenames Sean McBride Oct 14, 23:43
mlRe: Not so long filenames Chris Suter Oct 15, 03:32
mlRe: Not so long filenames Gerriet M. Denkman… Oct 15, 13:12
mlRe: Not so long filenames Gerriet M. Denkman… Oct 15, 13:19