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)
52static inline wchar_t *create_wchar_path(
const char *utf8)
60 count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,NULL,0);
61 if ((count > MAX_PATH) && (NTLongPathsEnabled() ==
MagickFalse))
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);
79 if ((count < 5) || (count >= 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
124static inline FILE *
fopen_utf8(
const char *path,
const char *mode)
126#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
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__)
174static inline int open_utf8(
const char *path,
int flags,mode_t mode)
176#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
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);
194static inline FILE *
popen_utf8(
const char *command,
const char *type)
196#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
197 return(popen(command,type));
210 length=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,5);
213 length=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0);
217 if (command_wide == (
wchar_t *) NULL)
219 length=MultiByteToWideChar(CP_UTF8,0,command,-1,command_wide,length);
221 file=_wpopen(command_wide,type_wide);
229#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
230#if defined(MAGICKCORE_HAVE_REALPATH)
231 return(realpath(path,(
char *) NULL));
259 if (path == (
const char *) NULL)
260 return((
char *) NULL);
261 length=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
263 return((
char *) NULL);
264 wide_path=(
wchar_t *) AcquireQuantumMeory(length,
sizeof(
wchar_t));
265 if (wide_path == (
wchar_t *) NULL)
266 return((
char *) NULL);
267 MultiByteToWideChar(CP_UTF8,0,path,-1,wide_path,length);
271 full_path_length=GetFullPathNameW(wide_path,0,NULL,NULL);
272 if (full_path_length == 0)
275 return((
char *) NULL);
278 if (full_path == (
wchar_t *) NULL);
281 return((
char *) NULL);
283 GetFullPathNameW(wide_path,full_path_length,full_path,NULL);
288 file_handle=CreateFileW(full_path,GENERIC_READ,FILE_SHARE_READ |
289 FILE_SHARE_WRITE | FILE_SHARE_DELETE,NULL,OPEN_EXISTING,
290 FILE_FLAG_BACKUP_SEMANTICS,NULL);
291 if (file_handle == INVALID_HANDLE_VALUE)
294 return((
char *) NULL);
299 final_path_length=GetFinalPathNameByHandleW(file_handle,NULL,0,
300 FILE_NAME_NORMALIZED);
301 if (final_path_length == 0)
303 CloseHandle(file_handle);
305 return((
char *) NULL);
309 if (final_path == (
wchar_t *) NULL)
311 CloseHandle(file_handle);
313 return((
char *) NULL);
315 GetFinalPathNameByHandleW(file_handle,final_path,final_path_length,
316 FILE_NAME_NORMALIZED);
317 CloseHandle(file_handle);
322 clean_path=final_path;
323 if (wcsncmp(final_path,L
"\\\\?\\",4) == 0)
324 clean_path=final_path+4;
328 utf8_length=WideCharToMultiByte(CP_UTF8,0,clean_path,-1,NULL,0,NULL,NULL);
329 if (utf8_length <= 0)
335 if (real_path == (
char *) NULL)
340 WideCharToMultiByte(CP_UTF8,0,clean_path,-1,real_path,utf8_length,NULL,NULL);
348#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
349 return(unlink(path));
357 path_wide=create_wchar_path(path);
358 if (path_wide == (
wchar_t *) NULL)
360 status=_wremove(path_wide);
366static inline int rename_utf8(
const char *source,
const char *destination)
368#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
369 return(rename(source,destination));
378 source_wide=create_wchar_path(source);
379 if (source_wide == (
wchar_t *) NULL)
381 destination_wide=create_wchar_path(destination);
382 if (destination_wide == (
wchar_t *) NULL)
387 status=_wrename(source_wide,destination_wide);
394static inline int stat_utf8(
const char *path,
struct stat *attributes)
396#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
397 return(stat(path,attributes));
405 path_wide=create_wchar_path(path);
406 if (path_wide == (WCHAR *) NULL)
408 status=wstat(path_wide,attributes);
416#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
417#if defined(MAGICKCORE_POSIX_SUPPORT)
421 if (lstat(path,&status) == -1)
428 return(NTIsSymlinkWide(path));
433#if defined(__cplusplus) || defined(c_plusplus)
MagickExport ssize_t FormatLocaleString(char *magick_restrict string, const size_t length, const char *magick_restrict format,...)
Definition: locale.c:497
MagickExport struct dirent * readdir(DIR *)
MagickBooleanType
Definition: magick-type.h:203
@ MagickFalse
Definition: magick-type.h:204
@ MagickTrue
Definition: magick-type.h:205
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1163
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:666
#define MagickPrivate
Definition: method-attribute.h:81
#define MaxTextExtent
Definition: method-attribute.h:89
MagickExport char * AcquireString(const char *source)
Definition: string.c:126
static int open_utf8(const char *path, int flags, mode_t mode)
Definition: utility-private.h:174
static int MagickReadDirectory(DIR *directory, struct dirent *entry, struct dirent **result)
Definition: utility-private.h:34
static FILE * fopen_utf8(const char *path, const char *mode)
Definition: utility-private.h:124
static int remove_utf8(const char *path)
Definition: utility-private.h:346
static char * realpath_utf8(const char *path)
Definition: utility-private.h:227
static int access_utf8(const char *path, int mode)
Definition: utility-private.h:98
static int stat_utf8(const char *path, struct stat *attributes)
Definition: utility-private.h:394
static void getcwd_utf8(char *path, size_t extent)
Definition: utility-private.h:152
MagickPrivate MagickBooleanType ShredFile(const char *)
Definition: utility.c:1954
static int rename_utf8(const char *source, const char *destination)
Definition: utility-private.h:366
static MagickBooleanType is_symlink_utf8(const char *path)
Definition: utility-private.h:414
static FILE * popen_utf8(const char *command, const char *type)
Definition: utility-private.h:194