• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Encoding to use for file names
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Encoding to use for file names


  • Subject: Re: Encoding to use for file names
  • From: Clark Cox <email@hidden>
  • Date: Thu, 5 Feb 2009 10:39:50 -0800

On Thu, Feb 5, 2009 at 9:41 AM, Nick Zitzmann <email@hidden> wrote:
>
> On Feb 5, 2009, at 10:29 AM, Francis Devereux wrote:
>
>> I have an NSString with a filename in it that I need to pass to the
>> portable code as a char *.  The portable code will then pass it to UNIX file
>> handling functions like fopen().
>>
>> I guess that I need to use NSString's getCString:maxLength:encoding:
>> method, but what should I pass for the encoding parameter?  Phrased another
>> way, what encoding does fopen() expect filenames to be in?
>
>
> You guessed incorrectly, actually. Always use -fileSystemRepresentation or
> -getFileSystemRepresentation:maxLength:.

While fileSystemRepresentation is the correct call to use, ...

> -UTF8String will incidentally work
> for HFS+ and UFS, but it probably won't work with legacy file systems that
> don't support Unicode, such as HFS.

... this is not correct. The encoding of strings passed to the
POSIX/BSD layer of the OS does not change based on the filesystem.
Passing a UTF-8 string to open() will work just fine on HFS, FAT-32,
UFS, whatever.

The point of using fileSystemRepresentation is to protect you against
changes in the future (i.e. if some new, UTF-better encoding comes
out, and Apple ever decides to use that encoding for their BSD calls.)

--
Clark S. Cox III
email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >Encoding to use for file names (From: Francis Devereux <email@hidden>)
 >Re: Encoding to use for file names (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: Saving application data in ~/Library/Application Support/
  • Next by Date: Re: Saving application data in ~/Library/Application Support/
  • Previous by thread: Re: Encoding to use for file names
  • Next by thread: Re: Encoding to use for file names
  • Index(es):
    • Date
    • Thread