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)
50 static 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);
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__)
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);
186 static inline FILE *
popen_utf8(
const char *command,
const char *type)
188 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
189 return(popen(command,type));
198 command_wide=create_wchar_path(command);
199 if (command_wide == (
wchar_t *) NULL)
200 return((FILE *) NULL);
201 type_wide=create_wchar_path(type);
202 if (type_wide == (
wchar_t *) NULL)
205 return((FILE *) NULL);
207 file=_wpopen(command_wide,type_wide);
216 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
217 return(unlink(path));
225 path_wide=create_wchar_path(path);
226 if (path_wide == (
wchar_t *) NULL)
228 status=_wremove(path_wide);
234 static inline int rename_utf8(
const char *source,
const char *destination)
236 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
237 return(rename(source,destination));
246 source_wide=create_wchar_path(source);
247 if (source_wide == (
wchar_t *) NULL)
249 destination_wide=create_wchar_path(destination);
250 if (destination_wide == (
wchar_t *) NULL)
255 status=_wrename(source_wide,destination_wide);
264 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
265 return(stat(path,attributes));
273 path_wide=create_wchar_path(path);
274 if (path_wide == (WCHAR *) NULL)
276 status=wstat(path_wide,attributes);
282 #if defined(__cplusplus) || defined(c_plusplus)
static FILE * popen_utf8(const char *command, const char *type)
Definition: utility-private.h:186
MagickExport ssize_t FormatLocaleString(char *magick_restrict string, const size_t length, const char *magick_restrict format,...)
Definition: locale.c:497
static void getcwd_utf8(char *path, size_t extent)
Definition: utility-private.h:144
char * path
Definition: type.h:56
static int stat_utf8(const char *path, struct stat *attributes)
Definition: utility-private.h:262
MagickBooleanType
Definition: magick-type.h:198
static int remove_utf8(const char *path)
Definition: utility-private.h:214
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:634
static FILE * fopen_utf8(const char *path, const char *mode)
Definition: utility-private.h:116
#define MaxTextExtent
Definition: method-attribute.h:89
static int open_utf8(const char *path, int flags, mode_t mode)
Definition: utility-private.h:166
MagickPrivate MagickBooleanType ShredFile(const char *)
Definition: utility.c:1815
Definition: magick-type.h:200
MagickExport struct dirent * readdir(DIR *)
static int rename_utf8(const char *source, const char *destination)
Definition: utility-private.h:234
static int access_utf8(const char *path, int mode)
Definition: utility-private.h:96
static int MagickReadDirectory(DIR *directory, struct dirent *entry, struct dirent **result)
Definition: utility-private.h:32
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1123
#define MagickPrivate
Definition: method-attribute.h:81