• 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: Unicode filenames with Apple File System and UIManagedDocument
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unicode filenames with Apple File System and UIManagedDocument


  • Subject: Re: Unicode filenames with Apple File System and UIManagedDocument
  • From: Alastair Houghton <email@hidden>
  • Date: Tue, 07 Mar 2017 18:19:15 +0000

On 7 Mar 2017, at 12:47, Jean-Daniel <email@hidden> wrote:
>
> Did you try to use NSString -fileSystemRepresentation instead of UTF-8, or even better, use URL. While using UTF-8 for path worked well on HFS+, It was never guaranteed to work on all FS.

FWIW, the macOS kernel does use UTF-8 at the VFS interface (and therefore the BSD syscalls that take path arguments expect UTF-8).  This is different to most other UNIXen (which tend to treat paths as a bunch of bytes, at least at syscall level and often at filesystem level too).  It’s definitely the case that for the built-in FAT, NTFS and HFS+ implementations, UTF-8 will work.  Other filesystem implementations really *should* be treating what they get as UTF-8 too, but obviously that’s not guaranteed.

AFAIK all -fileSystemRepresentation does is it processes the Unicode string according to the rules in TN1150 and then convert to UTF-8; but you don’t actually *need* to do the HFS+ mapping (TN1150) before calling the BSD API (and it doesn’t even make any sense to do so unless the filesystem is HFS+, which -fileSystemRepresentation has no way of knowing).  The main benefit is that the result will compare bytewise equal with a filename read from the filesystem (assuming HFS+).  On other filesystems, well, things are different.  VFAT and later variants store UTF-16, as does NTFS, but the rules in both cases differ.  ExtFS, UFS et al. tend to regard filenames as a bunch of bytes and don’t even try to record what encoding was used.  I don’t know what ZFS, XFS or JFS do; using Unicode at filesystem level on a UNIX-like system is not unproblematic (because it may very well *not* be the same encoding being used at the user’s terminal), but equally the bunch of bytes approach creates all kinds of fun (you may *see* a file with a particular name, but you can’t necessarily name it yourself from the keyboard...)

Not that I’d recommend *not* using -fileSystemRepresentation; Apple says we should, so we should.  I’m just observing that it isn’t a particularly good API and in future it’ll either be deprecated or do the exact same thing as -UTF8String because there’s really no other good option I can see.

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

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


  • Follow-Ups:
    • Re: Unicode filenames with Apple File System and UIManagedDocument
      • From: email@hidden
References: 
 >Unicode filenames with Apple File System and UIManagedDocument (From: email@hidden)
 >Re: Unicode filenames with Apple File System and UIManagedDocument (From: Jean-Daniel <email@hidden>)

  • Prev by Date: Re: Unicode filenames with Apple File System and UIManagedDocument
  • Next by Date: Re: Unicode filenames with Apple File System and UIManagedDocument
  • Previous by thread: Re: Unicode filenames with Apple File System and UIManagedDocument
  • Next by thread: Re: Unicode filenames with Apple File System and UIManagedDocument
  • Index(es):
    • Date
    • Thread