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);
103 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) 104 #define close_utf8 _close 106 #define close_utf8 close 111 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 112 return(fopen(path,mode));
121 path_wide=create_wchar_path(path);
122 if (path_wide == (
wchar_t *) NULL)
123 return((FILE *) NULL);
124 mode_wide=create_wchar_path(mode);
125 if (mode_wide == (
wchar_t *) NULL)
128 return((FILE *) NULL);
130 file=_wfopen(path_wide,mode_wide);
139 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 143 directory=getcwd(path,extent);
150 (void) WideCharToMultiByte(CP_UTF8,0,wide_path,-1,path,(
int) extent,NULL,NULL);
154 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__) 161 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 162 return(open(path,flags,mode));
170 path_wide=create_wchar_path(path);
171 if (path_wide == (
wchar_t *) NULL)
173 status=_wopen(path_wide,flags,mode);
179 static inline FILE *
popen_utf8(
const char *command,
const char *type)
181 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 182 return(popen(command,type));
191 command_wide=create_wchar_path(command);
192 if (command_wide == (
wchar_t *) NULL)
193 return((FILE *) NULL);
194 type_wide=create_wchar_path(type);
195 if (type_wide == (
wchar_t *) NULL)
198 return((FILE *) NULL);
200 file=_wpopen(command_wide,type_wide);
209 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) 210 #if defined(MAGICKCORE_HAVE_REALPATH) 211 return(realpath(path,(
char *) NULL));
239 if (path == (
const char *) NULL)
240 return((
char *) NULL);
241 length=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
243 return((
char *) NULL);
244 wide_path=(
wchar_t *) AcquireQuantumMeory(length,
sizeof(
wchar_t));
245 if (wide_path == (
wchar_t *) NULL)
246 return((
char *) NULL);
247 MultiByteToWideChar(CP_UTF8,0,path,-1,wide_path,length);
251 full_path_length=GetFullPathNameW(wide_path,0,NULL,NULL);
252 if (full_path_length == 0)
255 return((
char *) NULL);
258 if (full_path == (
wchar_t *) NULL);
261 return((
char *) NULL);
263 GetFullPathNameW(wide_path,full_path_length,full_path,NULL);
268 file_handle=CreateFileW(full_path,GENERIC_READ,FILE_SHARE_READ |
269 FILE_SHARE_WRITE | FILE_SHARE_DELETE,NULL,OPEN_EXISTING,
270 FILE_FLAG_BACKUP_SEMANTICS,NULL);
271 if (file_handle == INVALID_HANDLE_VALUE)
274 return((
char *) NULL);
279 final_path_length=GetFinalPathNameByHandleW(file_handle,NULL,0,
280 FILE_NAME_NORMALIZED);
281 if (final_path_length == 0)
283 CloseHandle(file_handle);
285 return((
char *) NULL);
289 if (final_path == (
wchar_t *) NULL)
291 CloseHandle(file_handle);
293 return((
char *) NULL);
295 GetFinalPathNameByHandleW(file_handle,final_path,final_path_length,
296 FILE_NAME_NORMALIZED);
297 CloseHandle(file_handle);
302 clean_path=final_path;
303 if (wcsncmp(final_path,L
"\\\\?\\",4) == 0)
304 clean_path=final_path+4;
308 utf8_length=WideCharToMultiByte(CP_UTF8,0,clean_path,-1,NULL,0,NULL,NULL);
309 if (utf8_length <= 0)
315 if (real_path == (
char *) NULL)
320 WideCharToMultiByte(CP_UTF8,0,clean_path,-1,real_path,utf8_length,NULL,NULL);
328 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 329 return(unlink(path));
337 path_wide=create_wchar_path(path);
338 if (path_wide == (
wchar_t *) NULL)
340 status=_wremove(path_wide);
346 static inline int rename_utf8(
const char *source,
const char *destination)
348 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 349 return(rename(source,destination));
358 source_wide=create_wchar_path(source);
359 if (source_wide == (
wchar_t *) NULL)
361 destination_wide=create_wchar_path(destination);
362 if (destination_wide == (
wchar_t *) NULL)
367 status=_wrename(source_wide,destination_wide);
376 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) 377 return(stat(path,attributes));
385 path_wide=create_wchar_path(path);
386 if (path_wide == (WCHAR *) NULL)
388 status=wstat(path_wide,attributes);
394 #if defined(__cplusplus) || defined(c_plusplus)
static FILE * popen_utf8(const char *command, const char *type)
Definition: utility-private.h:179
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:137
char * path
Definition: type.h:55
static int stat_utf8(const char *path, struct stat *attributes)
Definition: utility-private.h:374
MagickBooleanType
Definition: magick-type.h:215
MagickExport char * AcquireString(const char *source)
Definition: string.c:120
static int remove_utf8(const char *path)
Definition: utility-private.h:326
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:542
static FILE * fopen_utf8(const char *path, const char *mode)
Definition: utility-private.h:109
#define MaxTextExtent
Definition: method-attribute.h:106
static int open_utf8(const char *path, int flags, mode_t mode)
Definition: utility-private.h:159
MagickPrivate MagickBooleanType ShredFile(const char *)
Definition: utility.c:1799
static int rename_utf8(const char *source, const char *destination)
Definition: utility-private.h:346
static int access_utf8(const char *path, int mode)
Definition: utility-private.h:83
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1072
#define MagickPrivate
Definition: method-attribute.h:99
static char * realpath_utf8(const char *path)
Definition: utility-private.h:207