From 0cc9753f7f873bbcf8a528e05ab0adbd5c8fc79c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?=
Date: Mon, 27 Jan 2014 13:10:54 +0100
Subject: Change the default file name encoding mode to +fnaw
---
lib/kernel/doc/src/file.xml | 102 ++++++++++++++++++++++----------------------
1 file changed, 50 insertions(+), 52 deletions(-)
(limited to 'lib/kernel/doc')
diff --git a/lib/kernel/doc/src/file.xml b/lib/kernel/doc/src/file.xml
index 0a4dd3ba47..305b9fed2b 100644
--- a/lib/kernel/doc/src/file.xml
+++ b/lib/kernel/doc/src/file.xml
@@ -37,54 +37,48 @@
the file operations. See the command line flag
+A in erl(1).
- The Erlang VM supports file names in Unicode to a limited
- extent. Depending on how the VM is started (with the parameter
- +fnu or +fnl), file names given can contain
- characters > 255 and the VM system will convert file names
- back and forth to the native file name encoding.
+ With regard to file name encoding, the Erlang VM can operate in
+ two modes. The current mode can be queried using the native_name_encoding/0
+ function. It returns either latin1 or utf8.
- The default behavior for Unicode character translation depends
- on to what extent the underlying OS/filesystem enforces consistent
- naming. On OSes where all file names are ensured to be in one or
- another encoding, Unicode is the default (currently this holds for
- Windows and MacOSX). On OSes with completely transparent file
- naming (i.e. all Unixes except MacOSX), ISO-latin-1 file naming is
- the default. The reason for the ISO-latin-1 default is that
- file names are not guaranteed to be possible to interpret according to
- the Unicode encoding expected (i.e. UTF-8), and file names that
- cannot be decoded will only be accessible by using "raw
- file names", in other word file names given as binaries.
-
- As file names are traditionally not binaries in Erlang,
- applications that need to handle raw file names need to be
- converted, why the Unicode mode for file names is not default on
- systems having completely transparent file naming.
+ In the latin1 mode, the Erlang VM does not change the
+ encoding of file names. In the utf8 mode, file names can
+ contain Unicode characters greater than 255 and the VM will
+ convert file names back and forth to the native file name encoding
+ (usually UTF-8, but UTF-16 on Windows).
- Raw file names is a new feature in OTP R14B01, which allows the
- user to supply completely uninterpreted file names to the
- underlying OS/filesystem. They are supplied as binaries, where it
- is up to the user to supply a correct encoding for the
- environment. The function file:native_name_encoding() can
- be used to check what encoding the VM is working in. If the
- function returns latin1 file names are not in any way
- converted to Unicode, if it is utf8, raw file names should
- be encoded as UTF-8 if they are to follow the convention of the VM
- (and usually the convention of the OS as well). Using raw
- file names is useful if you have a filesystem with inconsistent
- file naming, where some files are named in UTF-8 encoding while
- others are not. A file:list_dir on such mixed file name systems
- when the VM is in Unicode file name mode might return file names as
- raw binaries as they cannot be interpreted as Unicode
- file names. Raw file names can also be used to give UTF-8 encoded
- file names even though the VM is not started in Unicode file name
- translation mode.
+ The default mode depends on the operating system. Windows and
+ MacOS X enforce consistent file name encoding and therefore the
+ VM uses the utf8 mode.
+
+ On operating systems with transparent naming (i.e. all Unix
+ systems except MacOS X), the default will be utf8 if the
+ terminal supports UTF-8, otherwise latin1. The default may
+ be overridden using the +fnl (to force latin1 mode)
+ or +fnu (to force utf8 mode) when starting erl.
+
+ On operating systems with transparent naming, files could be
+ inconsistently named, i.e. some files are encoded in UTF-8 while
+ others are encoded in (for example) iso-latin1. To be able to
+ handle file systems with inconsistent naming when running in the
+ utf8 mode, the concept of "raw file names" has been
+ introduced.
+
+ A raw file name is a file name given as a binary. The Erlang VM
+ will perform no translation of a file name given as a binary on
+ systems with transparent naming.
+
+ When running in the utf8 mode, the
+ file:list_dir/1 and file:read_link/1 functions will
+ never return raw file names. Use the list_dir_all/1 and read_link_all/1 functions to
+ return all file names including raw file names.
+
+ Also see Notes about raw file names.
- Note that on Windows, file:native_name_encoding()
- returns utf8 per default, which is the format for raw
- file names even on Windows, although the underlying OS specific
- code works in a limited version of little endian UTF16. As far as
- the Erlang programmer is concerned, Windows native Unicode format
- is UTF-8...
@@ -535,8 +529,8 @@
List all files in a directory
- Lists all the files in a directory, including files with
- "raw" names.
+
Lists all the files in a directory,
+ including files with "raw" names.
Returns {ok, Filenames} if successful.
Otherwise, it returns {error, Reason}.
Filenames is a list of
@@ -653,11 +647,14 @@
- Return the VM's configured filename encoding.
+ Return the VM's configured filename encoding
- This function returns the configured default file name encoding to use for raw file names. Generally an application supplying file names raw (as binaries), should obey the character encoding returned by this function.
- By default, the VM uses ISO-latin-1 file name encoding on filesystems and/or OSes that use completely transparent file naming. This includes all Unix versions except MacOSX, where the vfs layer enforces UTF-8 file naming. By giving the experimental option +fnu when starting Erlang, UTF-8 translation of file names can be turned on even for those systems. If Unicode file name translation is in effect, the system behaves as usual as long as file names conform to the encoding, but will return file names that are not properly encoded in UTF-8 as raw file names (i.e. binaries).
- On Windows, this function also returns utf8 by default. The OS uses a pure Unicode naming scheme and file names are always possible to interpret as valid Unicode. The fact that the underlying Windows OS actually encodes file names using little endian UTF-16 can be ignored by the Erlang programmer. Windows and MacOSX are the only operating systems where the VM operates in Unicode file name mode by default.
+ This function returns
+ the file name encoding mode. If it is latin1, the
+ system does no translation of file names. If it is
+ utf8, file names will be converted back and forth to
+ the native file name encoding (usually UTF-8, but UTF-16 on
+ Windows).
@@ -1450,7 +1447,8 @@
See what a link is pointing to
- This function returns {ok, Filename} if
+
This function returns
+ {ok, Filename} if
Name refers to a symbolic link that is
not a "raw" file name, or {error, Reason}
otherwise.
--
cgit v1.2.3