From 490f279c7e05e81bcc07e03c315aead27524f0a7 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 16 Apr 2020 09:14:07 +0300 Subject: [PATCH] File-handling cleanup in w32image.c * src/w32image.c (w32_load_image): Encode the image file name and convert it via 'map_w32_filename'. No need to do anything special when 'w32_unicode_filenames' is zero, since file names are in UTF-8 internally, and this code will never run on Windows 9X. * src/w32.h (map_w32_filename): Add prototype; removed prototypes from all *.c files. --- src/w32.c | 2 -- src/w32.h | 1 + src/w32fns.c | 1 - src/w32image.c | 19 ++++++++----------- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/w32.c b/src/w32.c index 80178029bd0..42c832a5937 100644 --- a/src/w32.c +++ b/src/w32.c @@ -3441,8 +3441,6 @@ is_fat_volume (const char * name, const char ** pPath) /* Convert all slashes in a filename to backslashes, and map filename to a valid 8.3 name if necessary. The result is a pointer to a static buffer, so CAVEAT EMPTOR! */ -const char *map_w32_filename (const char *, const char **); - const char * map_w32_filename (const char * name, const char ** pPath) { diff --git a/src/w32.h b/src/w32.h index cf1dadf64c0..1afb8ad0873 100644 --- a/src/w32.h +++ b/src/w32.h @@ -194,6 +194,7 @@ extern void syms_of_ntproc (void); extern void syms_of_ntterm (void); extern void dostounix_filename (register char *); extern void unixtodos_filename (register char *); +extern const char *map_w32_filename (const char *, const char **); 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 *); diff --git a/src/w32fns.c b/src/w32fns.c index 4f7cbed249d..e595b0285a7 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -80,7 +80,6 @@ along with GNU Emacs. If not, see . */ extern int w32_console_toggle_lock_key (int, Lisp_Object); extern void w32_menu_display_help (HWND, HMENU, UINT, UINT); extern void w32_free_menu_strings (HWND); -extern const char *map_w32_filename (const char *, const char **); #ifndef IDC_HAND #define IDC_HAND MAKEINTRESOURCE(32649) diff --git a/src/w32image.c b/src/w32image.c index fb36dc9a9f6..80c3247e97d 100644 --- a/src/w32image.c +++ b/src/w32image.c @@ -32,6 +32,9 @@ along with GNU Emacs. If not, see . */ #include #include "w32common.h" #include "w32term.h" +#ifdef WINDOWSNT +#include "w32.h" /* for map_w32_filename, filename_to_utf16 */ +#endif #include "frame.h" #include "coding.h" @@ -334,17 +337,11 @@ w32_load_image (struct frame *f, struct image *img, and succeeded. We have a valid token and GDI+ is active. */ if (STRINGP (spec_file)) { - if (w32_unicode_filenames) - { - wchar_t filename[MAX_PATH]; - filename_to_utf16 (SSDATA (spec_file), filename); - status = GdipCreateBitmapFromFile (filename, &pBitmap); - } - else - { - add_to_log ("GDI+ requires w32-unicode-filenames to be T"); - status = GenericError; - } + spec_file = ENCODE_FILE (spec_file); + const char *fn = map_w32_filename (SSDATA (spec_file), NULL); + wchar_t filename_w[MAX_PATH]; + filename_to_utf16 (fn, filename_w); + status = GdipCreateBitmapFromFile (filename_w, &pBitmap); } else if (STRINGP (spec_data)) { -- 2.39.5