18 #ifndef MAGICKCORE_UTILITY_PRIVATE_H 19 #define MAGICKCORE_UTILITY_PRIVATE_H 25 #if defined(__cplusplus) || defined(c_plusplus) 29 #define MagickPathTemplate "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 37 #if defined(MAGICKCORE_HAVE_READDIR_R) 38 return(readdir_r(directory,entry,result));
51 #if defined(MAGICKCORE_WINDOWS_SUPPORT) 52 static inline wchar_t *create_wchar_path(
const char *utf8)
60 count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,NULL,0);
73 if (longPath == (
wchar_t *) NULL)
74 return((
wchar_t *) NULL);
75 count=MultiByteToWideChar(CP_UTF8,0,buffer,-1,longPath,count);
77 count=GetShortPathNameW(longPath,shortPath,MAX_PATH);
80 return((
wchar_t *) NULL);
82 wcscpy(wideChar,shortPath+4);
86 if (wideChar == (
wchar_t *) NULL)
87 return((
wchar_t *) NULL);
88 count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,wideChar,count);
92 return((
wchar_t *) NULL);
100 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) 101 return(access(path,mode));
109 path_wide=create_wchar_path(path);
110 if (path_wide == (
wchar_t *) NULL)
112 status=_waccess(path_wide,mode);
118 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) 119 #define close_utf8 _close 121 #define close_utf8 close 126 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 127 return(fopen(path,mode));
136 path_wide=create_wchar_path(path);
137 if (path_wide == (
wchar_t *) NULL)
138 return((FILE *) NULL);
139 mode_wide=create_wchar_path(mode);
140 if (mode_wide == (
wchar_t *) NULL)
143 return((FILE *) NULL);
145 file=_wfopen(path_wide,mode_wide);
154 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) 158 directory=getcwd(path,extent);
165 (void) WideCharToMultiByte(CP_UTF8,0,wide_path,-1,path,(
int) extent,NULL,NULL);
169 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__) 176 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 177 return(open(path,flags,mode));
185 path_wide=create_wchar_path(path);
186 if (path_wide == (
wchar_t *) NULL)
188 status=_wopen(path_wide,flags,mode);
194 static inline FILE *
popen_utf8(
const char *command,
const char *type)
196 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 197 return(popen(command,type));
206 command_wide=create_wchar_path(command);
207 if (command_wide == (
wchar_t *) NULL)
208 return((FILE *) NULL);
209 type_wide=create_wchar_path(type);
210 if (type_wide == (
wchar_t *) NULL)
213 return((FILE *) NULL);
215 file=_wpopen(command_wide,type_wide);
224 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) 225 #if defined(MAGICKCORE_HAVE_REALPATH) 226 return(realpath(path,(
char *) NULL));
254 if (path == (
const char *) NULL)
255 return((
char *) NULL);
256 length=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
258 return((
char *) NULL);
259 wide_path=(
wchar_t *) AcquireQuantumMeory(length,
sizeof(
wchar_t));
260 if (wide_path == (
wchar_t *) NULL)
261 return((
char *) NULL);
262 MultiByteToWideChar(CP_UTF8,0,path,-1,wide_path,length);
266 full_path_length=GetFullPathNameW(wide_path,0,NULL,NULL);
267 if (full_path_length == 0)
270 return((
char *) NULL);
273 if (full_path == (
wchar_t *) NULL);
276 return((
char *) NULL);
278 GetFullPathNameW(wide_path,full_path_length,full_path,NULL);
283 file_handle=CreateFileW(full_path,GENERIC_READ,FILE_SHARE_READ |
284 FILE_SHARE_WRITE | FILE_SHARE_DELETE,NULL,OPEN_EXISTING,
285 FILE_FLAG_BACKUP_SEMANTICS,NULL);
286 if (file_handle == INVALID_HANDLE_VALUE)
289 return((
char *) NULL);
294 final_path_length=GetFinalPathNameByHandleW(file_handle,NULL,0,
295 FILE_NAME_NORMALIZED);
296 if (final_path_length == 0)
298 CloseHandle(file_handle);
300 return((
char *) NULL);
304 if (final_path == (
wchar_t *) NULL)
306 CloseHandle(file_handle);
308 return((
char *) NULL);
310 GetFinalPathNameByHandleW(file_handle,final_path,final_path_length,
311 FILE_NAME_NORMALIZED);
312 CloseHandle(file_handle);
317 clean_path=final_path;
318 if (wcsncmp(final_path,L
"\\\\?\\",4) == 0)
319 clean_path=final_path+4;
323 utf8_length=WideCharToMultiByte(CP_UTF8,0,clean_path,-1,NULL,0,NULL,NULL);
324 if (utf8_length <= 0)
330 if (real_path == (
char *) NULL)
335 WideCharToMultiByte(CP_UTF8,0,clean_path,-1,real_path,utf8_length,NULL,NULL);
343 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 344 return(unlink(path));
352 path_wide=create_wchar_path(path);
353 if (path_wide == (
wchar_t *) NULL)
355 status=_wremove(path_wide);
361 static inline int rename_utf8(
const char *source,
const char *destination)
363 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 364 return(rename(source,destination));
373 source_wide=create_wchar_path(source);
374 if (source_wide == (
wchar_t *) NULL)
376 destination_wide=create_wchar_path(destination);
377 if (destination_wide == (
wchar_t *) NULL)
382 status=_wrename(source_wide,destination_wide);
391 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 392 return(stat(path,attributes));
400 path_wide=create_wchar_path(path);
401 if (path_wide == (WCHAR *) NULL)
403 status=wstat(path_wide,attributes);
411 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) 416 if (lstat(path,&status) == -1)
423 return(NTIsSymlinkWide(path));
428 #if defined(__cplusplus) || defined(c_plusplus)
static FILE * popen_utf8(const char *command, const char *type)
Definition: utility-private.h:194
MagickExport ssize_t FormatLocaleString(char *magick_restrict string, const size_t length, const char *magick_restrict format,...)
Definition: locale.c:502
static void getcwd_utf8(char *path, size_t extent)
Definition: utility-private.h:152
char * path
Definition: type.h:56
static int stat_utf8(const char *path, struct stat *attributes)
Definition: utility-private.h:389
MagickBooleanType
Definition: magick-type.h:191
MagickExport char * AcquireString(const char *source)
Definition: string.c:126
static int remove_utf8(const char *path)
Definition: utility-private.h:341
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:547
static FILE * fopen_utf8(const char *path, const char *mode)
Definition: utility-private.h:124
#define MaxTextExtent
Definition: method-attribute.h:89
Definition: magick-type.h:194
static int open_utf8(const char *path, int flags, mode_t mode)
Definition: utility-private.h:174
MagickPrivate MagickBooleanType ShredFile(const char *)
Definition: utility.c:1933
Definition: magick-type.h:193
MagickExport struct dirent * readdir(DIR *)
static MagickBooleanType is_symlink_utf8(const char *path)
Definition: utility-private.h:409
static int rename_utf8(const char *source, const char *destination)
Definition: utility-private.h:361
static int access_utf8(const char *path, int mode)
Definition: utility-private.h:98
static int MagickReadDirectory(DIR *directory, struct dirent *entry, struct dirent **result)
Definition: utility-private.h:34
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1086
#define MagickPrivate
Definition: method-attribute.h:81
static char * realpath_utf8(const char *path)
Definition: utility-private.h:222