diff options
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/coding.c b/src/coding.c index ac828a48683..69b01553e7f 100644 --- a/src/coding.c +++ b/src/coding.c @@ -9473,6 +9473,49 @@ code_convert_string_norecord (Lisp_Object string, Lisp_Object coding_system, 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) +{ +#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, |
