From 2cc93c9c427929b244d983ae6241ca77bad2b88b Mon Sep 17 00:00:00 2001 From: dirk Date: Mon, 6 Apr 2015 16:49:12 +0000 Subject: [PATCH] Fixed UTF8 issue when determining the current working directory on Windows. --- MagickCore/utility-private.h | 17 +++++++++++++++++ MagickCore/utility.c | 4 +--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/MagickCore/utility-private.h b/MagickCore/utility-private.h index 4f0411a89..3ff6bb4a3 100644 --- a/MagickCore/utility-private.h +++ b/MagickCore/utility-private.h @@ -141,6 +141,23 @@ static inline FILE *fopen_utf8(const char *path,const char *mode) #endif } +static inline void getcwd_utf8(char *path,size_t extent) +{ +#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) + char + *directory; + + directory=getcwd(path,extent); + (void) directory; +#else + wchar_t + wide_path[MaxTextExtent]; + + (void) _wgetcwd(wide_path,MaxTextExtent-1); + (void) WideCharToMultiByte(CP_UTF8,0,wide_path,-1,path,(int) extent,NULL,NULL); +#endif +} + #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) typedef int mode_t; diff --git a/MagickCore/utility.c b/MagickCore/utility.c index bd5d1954a..9ccacb112 100644 --- a/MagickCore/utility.c +++ b/MagickCore/utility.c @@ -722,7 +722,6 @@ MagickExport MagickBooleanType ExpandFilenames(int *number_arguments, char ***arguments) { char - *directory, home_directory[MaxTextExtent], **vector; @@ -809,8 +808,7 @@ MagickExport MagickBooleanType ExpandFilenames(int *number_arguments, GetPathComponent(option,SubimagePath,subimage); ExpandFilename(path); if (*home_directory == '\0') - directory=getcwd(home_directory,MaxTextExtent-1); - (void) directory; + getcwd_utf8(home_directory,MaxTextExtent-1); filelist=ListFiles(*path == '\0' ? home_directory : path,filename, &number_files); } -- 2.40.0