aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/coding.c b/src/coding.c
index 6c0633f2d93..4ee55f7c8e6 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -9490,6 +9490,55 @@ code_convert_string_norecord (Lisp_Object string, Lisp_Object coding_system,
9490 return code_convert_string (string, coding_system, Qt, encodep, 0, 1); 9490 return code_convert_string (string, coding_system, Qt, encodep, 0, 1);
9491} 9491}
9492 9492
9493/* Encode or decode a file name, to or from a unibyte string suitable
9494 for passing to C library functions. */
9495Lisp_Object
9496decode_file_name (Lisp_Object fname)
9497{
9498#ifdef WINDOWSNT
9499 /* The w32 build pretends to use UTF-8 for file-name encoding, and
9500 converts the file names either to UTF-16LE or to the system ANSI
9501 codepage internally, depending on the underlying OS; see w32.c. */
9502 if (! NILP (Fcoding_system_p (Qutf_8)))
9503 return code_convert_string_norecord (fname, Qutf_8, 0);
9504 return fname;
9505#else /* !WINDOWSNT */
9506 if (! NILP (Vfile_name_coding_system))
9507 return code_convert_string_norecord (fname, Vfile_name_coding_system, 0);
9508 else if (! NILP (Vdefault_file_name_coding_system))
9509 return code_convert_string_norecord (fname,
9510 Vdefault_file_name_coding_system, 0);
9511 else
9512 return fname;
9513#endif
9514}
9515
9516Lisp_Object
9517encode_file_name (Lisp_Object fname)
9518{
9519 /* This is especially important during bootstrap and dumping, when
9520 file-name encoding is not yet known, and therefore any non-ASCII
9521 file names are unibyte strings, and could only be thrashed if we
9522 try to encode them. */
9523 if (!STRING_MULTIBYTE (fname))
9524 return fname;
9525#ifdef WINDOWSNT
9526 /* The w32 build pretends to use UTF-8 for file-name encoding, and
9527 converts the file names either to UTF-16LE or to the system ANSI
9528 codepage internally, depending on the underlying OS; see w32.c. */
9529 if (! NILP (Fcoding_system_p (Qutf_8)))
9530 return code_convert_string_norecord (fname, Qutf_8, 1);
9531 return fname;
9532#else /* !WINDOWSNT */
9533 if (! NILP (Vfile_name_coding_system))
9534 return code_convert_string_norecord (fname, Vfile_name_coding_system, 1);
9535 else if (! NILP (Vdefault_file_name_coding_system))
9536 return code_convert_string_norecord (fname,
9537 Vdefault_file_name_coding_system, 1);
9538 else
9539 return fname;
9540#endif
9541}
9493 9542
9494DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string, 9543DEFUN ("decode-coding-string", Fdecode_coding_string, Sdecode_coding_string,
9495 2, 4, 0, 9544 2, 4, 0,