18#ifndef MAGICKCORE_UTILITY_PRIVATE_H
19#define MAGICKCORE_UTILITY_PRIVATE_H
25#if defined(__cplusplus) || defined(c_plusplus)
35#if defined(MAGICKCORE_HAVE_READDIR_R)
36 return(readdir_r(directory,entry,result));
49#if defined(MAGICKCORE_WINDOWS_SUPPORT)
50static inline wchar_t *create_wchar_path(
const char *utf8)
58 count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,NULL,0);
59 if ((count > MAX_PATH) && (NTLongPathsEnabled() ==
MagickFalse))
71 if (longPath == (
wchar_t *) NULL)
72 return((
wchar_t *) NULL);
73 count=MultiByteToWideChar(CP_UTF8,0,buffer,-1,longPath,count);
75 count=GetShortPathNameW(longPath,shortPath,MAX_PATH);
77 if ((count < 5) || (count >= MAX_PATH))
78 return((
wchar_t *) NULL);
80 wcscpy(wideChar,shortPath+4);
84 if (wideChar == (
wchar_t *) NULL)
85 return((
wchar_t *) NULL);
86 count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,wideChar,count);
90 return((
wchar_t *) NULL);
98#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
99 return(access(path,mode));
107 path_wide=create_wchar_path(path);
108 if (path_wide == (
wchar_t *) NULL)
110 status=_waccess(path_wide,mode);
116static inline FILE *
fopen_utf8(
const char *path,
const char *mode)
118#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
119 return(fopen(path,mode));
128 path_wide=create_wchar_path(path);
129 if (path_wide == (
wchar_t *) NULL)
130 return((FILE *) NULL);
131 mode_wide=create_wchar_path(mode);
132 if (mode_wide == (
wchar_t *) NULL)
135 return((FILE *) NULL);
137 file=_wfopen(path_wide,mode_wide);
146#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
150 directory=getcwd(path,extent);
157 (void) WideCharToMultiByte(CP_UTF8,0,wide_path,-1,path,(
int) extent,NULL,NULL);
161#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__)
166static inline int open_utf8(
const char *path,
int flags,mode_t mode)
168#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
169 return(open(path,flags,mode));
177 path_wide=create_wchar_path(path);
178 if (path_wide == (
wchar_t *) NULL)
180 status=_wopen(path_wide,flags,mode);
186static inline FILE *
popen_utf8(
const char *command,
const char *type)
188#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
189 return(popen(command,type));
202 length=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,5);
205 length=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0);
209 if (command_wide == (
wchar_t *) NULL)
211 length=MultiByteToWideChar(CP_UTF8,0,command,-1,command_wide,length);
213 file=_wpopen(command_wide,type_wide);
221#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
222#if defined(MAGICKCORE_HAVE_REALPATH)
223 return(realpath(path,(
char *) NULL));
251 if (path == (
const char *) NULL)
252 return((
char *) NULL);
253 length=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
255 return((
char *) NULL);
256 wide_path=(
wchar_t *) AcquireQuantumMeory(length,
sizeof(
wchar_t));
257 if (wide_path == (
wchar_t *) NULL)
258 return((
char *) NULL);
259 MultiByteToWideChar(CP_UTF8,0,path,-1,wide_path,length);
263 full_path_length=GetFullPathNameW(wide_path,0,NULL,NULL);
264 if (full_path_length == 0)
267 return((
char *) NULL);
270 if (full_path == (
wchar_t *) NULL);
273 return((
char *) NULL);
275 GetFullPathNameW(wide_path,full_path_length,full_path,NULL);
280 file_handle=CreateFileW(full_path,GENERIC_READ,FILE_SHARE_READ |
281 FILE_SHARE_WRITE | FILE_SHARE_DELETE,NULL,OPEN_EXISTING,
282 FILE_FLAG_BACKUP_SEMANTICS,NULL);
283 if (file_handle == INVALID_HANDLE_VALUE)
286 return((
char *) NULL);
291 final_path_length=GetFinalPathNameByHandleW(file_handle,NULL,0,
292 FILE_NAME_NORMALIZED);
293 if (final_path_length == 0)
295 CloseHandle(file_handle);
297 return((
char *) NULL);
301 if (final_path == (
wchar_t *) NULL)
303 CloseHandle(file_handle);
305 return((
char *) NULL);
307 GetFinalPathNameByHandleW(file_handle,final_path,final_path_length,
308 FILE_NAME_NORMALIZED);
309 CloseHandle(file_handle);
314 clean_path=final_path;
315 if (wcsncmp(final_path,L
"\\\\?\\",4) == 0)
316 clean_path=final_path+4;
320 utf8_length=WideCharToMultiByte(CP_UTF8,0,clean_path,-1,NULL,0,NULL,NULL);
321 if (utf8_length <= 0)
327 if (real_path == (
char *) NULL)
332 WideCharToMultiByte(CP_UTF8,0,clean_path,-1,real_path,utf8_length,NULL,NULL);
340#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
341 return(unlink(path));
349 path_wide=create_wchar_path(path);
350 if (path_wide == (
wchar_t *) NULL)
352 status=_wremove(path_wide);
358static inline int rename_utf8(
const char *source,
const char *destination)
360#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
361 return(rename(source,destination));
370 source_wide=create_wchar_path(source);
371 if (source_wide == (
wchar_t *) NULL)
373 destination_wide=create_wchar_path(destination);
374 if (destination_wide == (
wchar_t *) NULL)
379 status=_wrename(source_wide,destination_wide);
386static inline int stat_utf8(
const char *path,
struct stat *attributes)
388#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
389 return(stat(path,attributes));
397 path_wide=create_wchar_path(path);
398 if (path_wide == (WCHAR *) NULL)
400 status=wstat(path_wide,attributes);
406#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
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1162
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:665
#define MagickPrivate
Definition: method-attribute.h:81
#define MaxTextExtent
Definition: method-attribute.h:89
MagickExport char * AcquireString(const char *source)
Definition: string.c:125
static int open_utf8(const char *path, int flags, mode_t mode)
Definition: utility-private.h:166
static int MagickReadDirectory(DIR *directory, struct dirent *entry, struct dirent **result)
Definition: utility-private.h:32
static FILE * fopen_utf8(const char *path, const char *mode)
Definition: utility-private.h:116
static int remove_utf8(const char *path)
Definition: utility-private.h:338
static char * realpath_utf8(const char *path)
Definition: utility-private.h:219
static int access_utf8(const char *path, int mode)
Definition: utility-private.h:96
static int stat_utf8(const char *path, struct stat *attributes)
Definition: utility-private.h:386
static void getcwd_utf8(char *path, size_t extent)
Definition: utility-private.h:144
MagickPrivate MagickBooleanType ShredFile(const char *)
Definition: utility.c:1836
static int rename_utf8(const char *source, const char *destination)
Definition: utility-private.h:358
static FILE * popen_utf8(const char *command, const char *type)
Definition: utility-private.h:186