From b45af5f9608d5dc79a5f201afdcc9a7e28e7ba83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 27 Feb 2014 12:41:53 +0100 Subject: Correct file:set_cwd/1 typespec file:set_cwd/1 accepts binaries as arguments, however the binaries must be properly encoded as per file:native_name_encoding/0. Also update the note under no_translation error to refer that passing a ISO-latin-1 encoded binary under any unicode file name encoding. --- lib/kernel/doc/src/file.xml | 9 +++++++-- lib/kernel/src/file.erl | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/kernel/doc/src/file.xml b/lib/kernel/doc/src/file.xml index 66ecba1bf2..71db9b66bd 100644 --- a/lib/kernel/doc/src/file.xml +++ b/lib/kernel/doc/src/file.xml @@ -1622,6 +1622,11 @@

Sets the current working directory of the file server to Dir. Returns ok if successful.

+

The functions in the file module usually treat binaries + as raw filenames, i.e. they are passed as is even when the encoding + of the binary does not agree with file:native_name_encoding(). + This function however expects binaries to be encoded according to the + value returned by file:native_name_encoding().

Typical error reasons are:

enoent @@ -1646,8 +1651,8 @@ no_translation

Dir is a binary() with - characters coded in ISO-latin-1 and the VM was started - with the parameter +fnue.

+ characters coded in ISO-latin-1 and the VM is operating + with unicode file name encoding.

diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl index 36289053eb..5467175654 100644 --- a/lib/kernel/src/file.erl +++ b/lib/kernel/src/file.erl @@ -197,7 +197,8 @@ get_cwd(Drive) -> check_and_call(get_cwd, [file_name(Drive)]). -spec set_cwd(Dir) -> ok | {error, Reason} when - Dir :: name(), + Dir :: name() | EncodedBinary, + EncodedBinary :: binary(), Reason :: posix() | badarg | no_translation. set_cwd(Dirname) -> -- cgit v1.2.3