POSIX_filename_encoding.txt 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. http://www.linuxfromscratch.org/blfs/view/svn/introduction/locale-issues.html
  2. "The POSIX standard mandates that the filename encoding is the encoding implied by the current LC_CTYPE locale category."
  3. -------
  4. http://mail.nl.linux.org/linux-utf8/2001-02/msg00103.html
  5. From: Markus Kuhn
  6. Tom Tromey wrote on 2001-02-05 00:36 UTC:
  7. > Kai> IMAO, a *real* filesystem should use some encoding of ISO 10646 -
  8. > Kai> UTF-8, UTF-16, or UTF-32 are all viable options. The same should
  9. > Kai> be true for the kernel filename interfaces.
  10. >
  11. > I like this, but what should I do right now?
  12. The POSIX kernel file system interface is engraved into stone and
  13. extremely unlikely to change. File names are arbitrary binary strings,
  14. with only the '/' and '\0' bytes having any special semantics. You can
  15. use arbitrary coded character sets on it as long as they do not
  16. introduce '/' and '\0' bytes spuriously. Writers and readers have to
  17. somehow agree on what encoding to use and the only really practical way
  18. is to use the same encoding on all systems that share files. Eventually,
  19. everyone will be using UTF-8 for file names on POSIX systems. Right now,
  20. I would recommend users to use only ASCII for filenames, as this is
  21. already UTF-8 and therefore simplifies migration. Using the ISO 8859,
  22. JIS, etc. filenames should soon be considered deprecated practice.
  23. > I work on libgcj, the runtime component of gcj, the Java front end to
  24. > GCC. In libgcj of course we use UCS-2 everywhere, since that is what
  25. > Java does. Currently, for Unixy systems, we assume that all file
  26. > names are UTF-8.
  27. The best solution is to assume that the file names are in the
  28. locale-specific multi-byte encoding. Simply use mbrtowc and wcrtomb to
  29. convert between Unicode and the locale-dependent multi-byte encoding
  30. used in file names and text files if the ISO C 99 symbol
  31. __STDC_ISO_10646__ is defined (which guarantees that wchar_t = UCS). On
  32. Linux, this has been the case since glibc 2.2.
  33. > (Actually, we do something notably worse, which is
  34. > assume that file names are Java-style UTF-8, with the weird encoding
  35. > for \u0000.)
  36. \u0000 = NUL was never a character allowed in filenames under POSIX.
  37. Raise an exception if someone tries to use it in a filename. Problem
  38. solved.
  39. I never understood, why Java found it necessary to introduce two
  40. distinct ASCII NUL characters.
  41. ------
  42. Interesting idea. Use iconv to create shift-jis or other mbcs test cases.