From: Eli Zaretskii Date: Tue, 3 Dec 2013 15:29:48 +0000 (+0200) Subject: Converted image.c and gnutls.c functions that accept file names. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~446^2~24 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9ab69568723b5f3e7c668ab6de2b383106f84c2d;p=emacs.git Converted image.c and gnutls.c functions that accept file names. --- diff --git a/src/gnutls.c b/src/gnutls.c index 82b2fc8baa4..19617cea4b2 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -21,6 +21,7 @@ along with GNU Emacs. If not, see . */ #include "lisp.h" #include "process.h" +#include "coding.h" #ifdef HAVE_GNUTLS #include @@ -895,6 +896,13 @@ one trustfile (usually a CA bundle). */) { GNUTLS_LOG2 (1, max_log_level, "setting the trustfile: ", SSDATA (trustfile)); + trustfile = ENCODE_FILE (trustfile); +#ifdef WINDOWSNT + /* Since GnuTLS doesn't support UTF-8 or UTF-16 encoded + file names on Windows, we need to re-encode the file + name using the current ANSI codepage. */ + trustfile = ansi_encode_filename (trustfile); +#endif ret = fn_gnutls_certificate_set_x509_trust_file (x509_cred, SSDATA (trustfile), @@ -917,6 +925,10 @@ one trustfile (usually a CA bundle). */) { GNUTLS_LOG2 (1, max_log_level, "setting the CRL file: ", SSDATA (crlfile)); + crlfile = ENCODE_FILE (crlfile); +#ifdef WINDOWSNT + crlfile = ansi_encode_filename (crlfile); +#endif ret = fn_gnutls_certificate_set_x509_crl_file (x509_cred, SSDATA (crlfile), file_format); @@ -940,6 +952,12 @@ one trustfile (usually a CA bundle). */) SSDATA (keyfile)); GNUTLS_LOG2 (1, max_log_level, "setting the client cert file: ", SSDATA (certfile)); + keyfile = ENCODE_FILE (keyfile); + certfile = ENCODE_FILE (certfile); +#ifdef WINDOWSNT + keyfile = ansi_encode_filename (keyfile); + certfile = ansi_encode_filename (certfile); +#endif ret = fn_gnutls_certificate_set_x509_key_file (x509_cred, SSDATA (certfile), SSDATA (keyfile), file_format); diff --git a/src/image.c b/src/image.c index 37a19e4f5a5..89e4f863d53 100644 --- a/src/image.c +++ b/src/image.c @@ -3590,6 +3590,12 @@ xpm_load (struct frame *f, struct image *img) } #ifdef HAVE_NTGUI +#ifdef WINDOWSNT + /* FILE is encoded in UTF-8, but image libraries on Windows + support neither UTF-8 nor UTF-16 encoded file names. So we + need to re-encode it in ANSI. */ + file = ansi_encode_filename (file); +#endif /* XpmReadFileToPixmap is not available in the Windows port of libxpm. But XpmReadFileToImage almost does what we want. */ rc = fn_XpmReadFileToImage (&hdc, SDATA (file), @@ -6968,6 +6974,9 @@ tiff_load (struct frame *f, struct image *img) image_error ("Cannot find image file `%s'", specified_file, Qnil); return 0; } +#ifdef WINDOWSNT + file = ansi_encode_filename (file); +#endif /* Try to open the image file. */ tiff = fn_TIFFOpen (SSDATA (file), "r"); @@ -7353,6 +7362,9 @@ gif_load (struct frame *f, struct image *img) image_error ("Cannot find image file `%s'", specified_file, Qnil); return 0; } +#ifdef WINDOWSNT + file = ansi_encode_filename (file); +#endif /* Open the GIF file. */ #if GIFLIB_MAJOR < 5 @@ -8479,6 +8491,9 @@ imagemagick_load (struct frame *f, struct image *img) image_error ("Cannot find image file `%s'", file_name, Qnil); return 0; } +#ifdef WINDOWSNT + file = ansi_encode_filename (file); +#endif success_p = imagemagick_load_image (f, img, 0, 0, SSDATA (file)); } /* Else its not a file, its a lisp object. Load the image from a diff --git a/src/w32.c b/src/w32.c index 0080628e563..7d1ebebc68b 100644 --- a/src/w32.c +++ b/src/w32.c @@ -2135,6 +2135,36 @@ w32_get_short_filename (char * name, char * buf, int size) } } +/* Re-encode FILENAME, a UTF-8 encoded unibyte string, using the + MS-Windows ANSI codepage. If FILENAME includes characters not + supported by the ANSI codepage, return the 8+3 alias of FILENAME, + if it exists. This is needed because the w32 build wants to + support file names outside of the system locale, but image + libraries typically don't support wide (a.k.a. "Unicode") APIs + required for that. */ + +Lisp_Object +ansi_encode_filename (Lisp_Object filename) +{ + Lisp_Object encoded_filename; + char fname[MAX_PATH]; + + filename_to_ansi (SSDATA (filename), fname); + if (_mbspbrk (fname, "?")) + { + char shortname[MAX_PATH]; + + if (w32_get_short_filename (SDATA (filename), shortname, MAX_PATH)) + { + dostounix_filename (shortname); + encoded_filename = build_string (shortname); + } + } + else + encoded_filename = build_unibyte_string (fname); + return encoded_filename; +} + static int is_unc_volume (const char *filename) { diff --git a/src/w32.h b/src/w32.h index d542083438f..cca95855a78 100644 --- a/src/w32.h +++ b/src/w32.h @@ -184,6 +184,7 @@ extern int filename_from_ansi (const char *, char *); extern int filename_to_ansi (const char *, char *); extern int filename_from_utf16 (const wchar_t *, char *); extern int filename_to_utf16 (const char *, wchar_t *); +extern Lisp_Object ansi_encode_filename (Lisp_Object); extern BOOL init_winsock (int load_now); extern void srandom (int);