From 320684d8947c00dca0518767958f6122b85716e9 Mon Sep 17 00:00:00 2001 From: cristy Date: Fri, 23 Sep 2011 14:55:47 +0000 Subject: [PATCH] --- MagickCore/cache.c | 2 +- MagickCore/utility-private.h | 43 +++++++++++++++++++++++++++++++----- MagickWand/mogrify.c | 2 +- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/MagickCore/cache.c b/MagickCore/cache.c index 8f02a6dca..c64769d49 100644 --- a/MagickCore/cache.c +++ b/MagickCore/cache.c @@ -4287,7 +4287,7 @@ MagickExport MagickBooleanType PersistPixelCache(Image *image, /* Usurp existing persistent pixel cache. */ - status=rename(cache_info->cache_filename,filename); + status=rename_utf8(cache_info->cache_filename,filename); if (status == 0) { (void) CopyMagickString(cache_info->cache_filename,filename, diff --git a/MagickCore/utility-private.h b/MagickCore/utility-private.h index 5f5886fe0..d3f8573bc 100644 --- a/MagickCore/utility-private.h +++ b/MagickCore/utility-private.h @@ -73,9 +73,6 @@ static inline FILE *fopen_utf8(const char *path,const char *mode) FILE *file; - int - status; - WCHAR *mode_wide, *path_wide; @@ -133,9 +130,6 @@ static inline FILE *popen_utf8(const char *command,const char *type) FILE *file; - int - status; - WCHAR *type_wide, *command_wide; @@ -185,6 +179,43 @@ static inline int remove_utf8(const char *path) #endif } +static inline int rename_utf8(const char *source,const char *destination) +{ +#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) + return(rename(source,destination)); +#else + FILE + *file; + + int + status; + + WCHAR + *destination_wide, + *source_wide; + + source_wide=(WCHAR *) NULL; + count=MultiByteToWideChar(CP_UTF8,0,source,-1,NULL,0); + source_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*source_wide)); + if (source_wide == (WCHAR *) NULL) + return(-1); + count=MultiByteToWideChar(CP_UTF8,0,source,-1,source_wide,count); + count=MultiByteToWideChar(CP_UTF8,0,destination,-1,NULL,0); + destination_wide=(WCHAR *) AcquireQuantumMemory(count, + sizeof(*destination_wide)); + if (destination_wide == (WCHAR *) NULL) + { + source_wide=RelinquishMagickMemory(source_wide); + return(-1); + } + count=MultiByteToWideChar(CP_UTF8,0,destination,-1,destination_wide,count); + status=_wrename(path_wide,destination_width); + destination_wide=RelinquishMagickMemory(destination_wide); + path_wide=RelinquishMagickMemory(path_wide); + return(status); +#endif +} + static inline int stat_utf8(const char *path,struct stat *attributes) { #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) diff --git a/MagickWand/mogrify.c b/MagickWand/mogrify.c index 0167c3790..0b65e0801 100644 --- a/MagickWand/mogrify.c +++ b/MagickWand/mogrify.c @@ -3736,7 +3736,7 @@ WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info, break; } if ((IsPathAccessible(backup_filename) != MagickFalse) || - (rename(image->filename,backup_filename) != 0)) + (rename_utf8(image->filename,backup_filename) != 0)) *backup_filename='\0'; } /* -- 2.40.0