18 #ifndef MAGICKCORE_UTILITY_PRIVATE_H 19 #define MAGICKCORE_UTILITY_PRIVATE_H 25 #if defined(__cplusplus) || defined(c_plusplus) 36 #if defined(MAGICKCORE_WINDOWS_SUPPORT) 37 static inline wchar_t *create_wchar_path(
const char *utf8)
45 count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,NULL,0);
58 if (longPath == (
wchar_t *) NULL)
59 return((
wchar_t *) NULL);
60 count=MultiByteToWideChar(CP_UTF8,0,buffer,-1,longPath,count);
62 count=GetShortPathNameW(longPath,shortPath,MAX_PATH);
65 return((
wchar_t *) NULL);
67 wcscpy(wideChar,shortPath+4);
71 if (wideChar == (
wchar_t *) NULL)
72 return((
wchar_t *) NULL);
73 count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,wideChar,count);
77 return((
wchar_t *) NULL);
85 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) 86 return(access(path,mode));
94 path_wide=create_wchar_path(path);
95 if (path_wide == (
wchar_t *) NULL)
97 status=_waccess(path_wide,mode);
105 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 106 return(fopen(path,mode));
115 path_wide=create_wchar_path(path);
116 if (path_wide == (
wchar_t *) NULL)
117 return((FILE *) NULL);
118 mode_wide=create_wchar_path(mode);
119 if (mode_wide == (
wchar_t *) NULL)
122 return((FILE *) NULL);
124 file=_wfopen(path_wide,mode_wide);
133 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 137 directory=getcwd(path,extent);
144 (void) WideCharToMultiByte(CP_UTF8,0,wide_path,-1,path,(
int) extent,NULL,NULL);
148 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) 155 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 156 return(open(path,flags,mode));
164 path_wide=create_wchar_path(path);
165 if (path_wide == (
wchar_t *) NULL)
167 status=_wopen(path_wide,flags,mode);
173 static inline FILE *
popen_utf8(
const char *command,
const char *type)
175 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 176 return(popen(command,type));
185 command_wide=create_wchar_path(command);
186 if (command_wide == (
wchar_t *) NULL)
187 return((FILE *) NULL);
188 type_wide=create_wchar_path(type);
189 if (type_wide == (
wchar_t *) NULL)
192 return((FILE *) NULL);
194 file=_wpopen(command_wide,type_wide);
203 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) 204 #if defined(MAGICKCORE_HAVE_REALPATH) 205 return(realpath(path,(
char *) NULL));
233 if (path == (
const char *) NULL)
234 return((
char *) NULL);
235 length=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
237 return((
char *) NULL);
238 wide_path=(
wchar_t *) AcquireQuantumMeory(length,
sizeof(
wchar_t));
239 if (wide_path == (
wchar_t *) NULL)
240 return((
char *) NULL);
241 MultiByteToWideChar(CP_UTF8,0,path,-1,wide_path,length);
245 full_path_length=GetFullPathNameW(wide_path,0,NULL,NULL);
246 if (full_path_length == 0)
249 return((
char *) NULL);
252 if (full_path == (
wchar_t *) NULL);
255 return((
char *) NULL);
257 GetFullPathNameW(wide_path,full_path_length,full_path,NULL);
262 file_handle=CreateFileW(full_path,GENERIC_READ,FILE_SHARE_READ |
263 FILE_SHARE_WRITE | FILE_SHARE_DELETE,NULL,OPEN_EXISTING,
264 FILE_FLAG_BACKUP_SEMANTICS,NULL);
265 if (file_handle == INVALID_HANDLE_VALUE)
268 return((
char *) NULL);
273 final_path_length=GetFinalPathNameByHandleW(file_handle,NULL,0,
274 FILE_NAME_NORMALIZED);
275 if (final_path_length == 0)
277 CloseHandle(file_handle);
279 return((
char *) NULL);
283 if (final_path == (
wchar_t *) NULL)
285 CloseHandle(file_handle);
287 return((
char *) NULL);
289 GetFinalPathNameByHandleW(file_handle,final_path,final_path_length,
290 FILE_NAME_NORMALIZED);
291 CloseHandle(file_handle);
296 clean_path=final_path;
297 if (wcsncmp(final_path,L
"\\\\?\\",4) == 0)
298 clean_path=final_path+4;
302 utf8_length=WideCharToMultiByte(CP_UTF8,0,clean_path,-1,NULL,0,NULL,NULL);
303 if (utf8_length <= 0)
309 if (real_path == (
char *) NULL)
314 WideCharToMultiByte(CP_UTF8,0,clean_path,-1,real_path,utf8_length,NULL,NULL);
322 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 323 return(unlink(path));
331 path_wide=create_wchar_path(path);
332 if (path_wide == (
wchar_t *) NULL)
334 status=_wremove(path_wide);
340 static inline int rename_utf8(
const char *source,
const char *destination)
342 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 343 return(rename(source,destination));
352 source_wide=create_wchar_path(source);
353 if (source_wide == (
wchar_t *) NULL)
355 destination_wide=create_wchar_path(destination);
356 if (destination_wide == (
wchar_t *) NULL)
361 status=_wrename(source_wide,destination_wide);
370 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 371 return(stat(path,attributes));
379 path_wide=create_wchar_path(path);
380 if (path_wide == (WCHAR *) NULL)
382 status=wstat(path_wide,attributes);
388 #if defined(__cplusplus) || defined(c_plusplus)
static FILE * popen_utf8(const char *command, const char *type)
Definition: utility-private.h:173
MagickExport ssize_t FormatLocaleString(char *magick_restrict string, const size_t length, const char *magick_restrict format,...)
Definition: locale.c:470
static void getcwd_utf8(char *path, size_t extent)
Definition: utility-private.h:131
char * path
Definition: type.h:55
static int stat_utf8(const char *path, struct stat *attributes)
Definition: utility-private.h:368
MagickBooleanType
Definition: magick-type.h:214
MagickExport char * AcquireString(const char *source)
Definition: string.c:120
static int remove_utf8(const char *path)
Definition: utility-private.h:320
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:526
static FILE * fopen_utf8(const char *path, const char *mode)
Definition: utility-private.h:103
#define MaxTextExtent
Definition: method-attribute.h:106
static int open_utf8(const char *path, int flags, mode_t mode)
Definition: utility-private.h:153
MagickPrivate MagickBooleanType ShredFile(const char *)
Definition: utility.c:1799
static int rename_utf8(const char *source, const char *destination)
Definition: utility-private.h:340
static int access_utf8(const char *path, int mode)
Definition: utility-private.h:83
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:998
#define MagickPrivate
Definition: method-attribute.h:99
static char * realpath_utf8(const char *path)
Definition: utility-private.h:201