From: Eli Zaretskii Date: Mon, 18 Nov 2013 16:45:48 +0000 (+0200) Subject: Merge from mainline. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~446^2~34 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=18b35e2c7a3ff95fb4a07e58c3f57c70c65c0701;p=emacs.git Merge from mainline. --- 18b35e2c7a3ff95fb4a07e58c3f57c70c65c0701 diff --cc src/coding.c index 69b01553e7f,6c0633f2d93..4ee55f7c8e6 --- a/src/coding.c +++ b/src/coding.c @@@ -9473,49 -9490,6 +9490,55 @@@ code_convert_string_norecord (Lisp_Obje return code_convert_string (string, coding_system, Qt, encodep, 0, 1); } +/* Encode or decode a file name, to or from a unibyte string suitable + for passing to C library functions. */ +Lisp_Object +decode_file_name (Lisp_Object fname) +{ +#ifdef WINDOWSNT + /* The w32 build pretends to use UTF-8 for file-name encoding, and + converts the file names either to UTF-16LE or to the system ANSI + codepage internally, depending on the underlying OS; see w32.c. */ + if (! NILP (Fcoding_system_p (Qutf_8))) + return code_convert_string_norecord (fname, Qutf_8, 0); + return fname; +#else /* !WINDOWSNT */ + if (! NILP (Vfile_name_coding_system)) + return code_convert_string_norecord (fname, Vfile_name_coding_system, 0); + else if (! NILP (Vdefault_file_name_coding_system)) + return code_convert_string_norecord (fname, + Vdefault_file_name_coding_system, 0); + else + return fname; +#endif +} + +Lisp_Object +encode_file_name (Lisp_Object fname) +{ ++ /* This is especially important during bootstrap and dumping, when ++ file-name encoding is not yet known, and therefore any non-ASCII ++ file names are unibyte strings, and could only be thrashed if we ++ try to encode them. */ ++ if (!STRING_MULTIBYTE (fname)) ++ return fname; +#ifdef WINDOWSNT + /* The w32 build pretends to use UTF-8 for file-name encoding, and + converts the file names either to UTF-16LE or to the system ANSI + codepage internally, depending on the underlying OS; see w32.c. */ + if (! NILP (Fcoding_system_p (Qutf_8))) + return code_convert_string_norecord (fname, Qutf_8, 1); + return fname; +#else /* !WINDOWSNT */ + if (! NILP (Vfile_name_coding_system)) + return code_convert_string_norecord (fname, Vfile_name_coding_system, 1); + else if (! NILP (Vdefault_file_name_coding_system)) + return code_convert_string_norecord (fname, + Vdefault_file_name_coding_system, 1); + else + return fname; +#endif +} DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, 2, 4, 0,