18 #ifndef MAGICKCORE_UTILITY_PRIVATE_H
19 #define MAGICKCORE_UTILITY_PRIVATE_H
25 #if defined(__cplusplus) || defined(c_plusplus)
31 **
ListFiles(
const char *,
const char *,
size_t *);
45 struct dirent **result)
47 #if defined(MAGICKCORE_HAVE_READDIR_R)
48 return(readdir_r(directory,entry,result));
52 *result=readdir(directory);
61 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
62 static inline wchar_t *create_wchar_path(
const char *utf8)
70 count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,NULL,0);
71 if ((count > MAX_PATH) && (NTLongPathsEnabled() ==
MagickFalse))
83 if (longPath == (
wchar_t *) NULL)
84 return((
wchar_t *) NULL);
85 count=MultiByteToWideChar(CP_UTF8,0,buffer,-1,longPath,count);
87 count=GetShortPathNameW(longPath,shortPath,MAX_PATH);
89 if ((count < 5) || (count >= MAX_PATH))
90 return((
wchar_t *) NULL);
92 wcscpy(wideChar,shortPath+4);
96 if (wideChar == (
wchar_t *) NULL)
97 return((
wchar_t *) NULL);
98 count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,wideChar,count);
102 return((
wchar_t *) NULL);
110 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
111 return(access(path,mode));
119 path_wide=create_wchar_path(path);
120 if (path_wide == (
wchar_t *) NULL)
122 status=_waccess(path_wide,mode);
128 static inline FILE *
fopen_utf8(
const char *path,
const char *mode)
130 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
131 return(fopen(path,mode));
140 path_wide=create_wchar_path(path);
141 if (path_wide == (
wchar_t *) NULL)
142 return((FILE *) NULL);
143 mode_wide=create_wchar_path(mode);
144 if (mode_wide == (
wchar_t *) NULL)
147 return((FILE *) NULL);
149 file=_wfopen(path_wide,mode_wide);
158 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
162 directory=getcwd(path,extent);
169 (void) WideCharToMultiByte(CP_UTF8,0,wide_path,-1,path,(
int) extent,NULL,NULL);
173 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__)
178 static inline int open_utf8(
const char *path,
int flags,mode_t mode)
180 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
181 return(open(path,flags,mode));
189 path_wide=create_wchar_path(path);
190 if (path_wide == (
wchar_t *) NULL)
192 status=_wopen(path_wide,flags,mode);
198 static inline FILE *
popen_utf8(
const char *command,
const char *type)
200 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
201 return(popen(command,type));
210 command_wide=create_wchar_path(command);
211 if (command_wide == (
wchar_t *) NULL)
212 return((FILE *) NULL);
213 type_wide=create_wchar_path(type);
214 if (type_wide == (
wchar_t *) NULL)
217 return((FILE *) NULL);
219 file=_wpopen(command_wide,type_wide);
228 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
229 return(unlink(path));
237 path_wide=create_wchar_path(path);
238 if (path_wide == (
wchar_t *) NULL)
240 status=_wremove(path_wide);
246 static inline int rename_utf8(
const char *source,
const char *destination)
248 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
249 return(rename(source,destination));
258 source_wide=create_wchar_path(source);
259 if (source_wide == (
wchar_t *) NULL)
261 destination_wide=create_wchar_path(destination);
262 if (destination_wide == (
wchar_t *) NULL)
267 status=_wrename(source_wide,destination_wide);
274 static inline int stat_utf8(
const char *path,
struct stat *attributes)
276 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
277 return(stat(path,attributes));
285 path_wide=create_wchar_path(path);
286 if (path_wide == (WCHAR *) NULL)
288 status=wstat(path_wide,attributes);
294 #if defined(__cplusplus) || defined(c_plusplus)
static FILE * popen_utf8(const char *command, const char *type)
Definition: utility-private.h:198
MagickExport ssize_t FormatLocaleString(char *magick_restrict string, const size_t length, const char *magick_restrict format,...)
Definition: locale.c:499
static void getcwd_utf8(char *path, size_t extent)
Definition: utility-private.h:156
static int stat_utf8(const char *path, struct stat *attributes)
Definition: utility-private.h:274
MagickBooleanType
Definition: magick-type.h:169
MagickPrivate ssize_t GetMagickPageSize(void)
Definition: utility.c:1134
static int remove_utf8(const char *path)
Definition: utility-private.h:226
MagickPrivate void ExpandFilename(char *)
Definition: utility.c:616
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:128
#define MagickPathExtent
Definition: method-attribute.h:88
static int open_utf8(const char *path, int flags, mode_t mode)
Definition: utility-private.h:178
MagickPrivate MagickBooleanType ShredFile(const char *)
Definition: utility.c:1831
MagickPrivate char ** GetPathComponents(const char *, size_t *)
MagickPrivate char ** ListFiles(const char *, const char *, size_t *)
Definition: utility.c:1596
MagickPrivate MagickBooleanType GetExecutionPath(char *, const size_t)
Definition: magick-type.h:171
static int rename_utf8(const char *source, const char *destination)
Definition: utility-private.h:246
static int access_utf8(const char *path, int mode)
Definition: utility-private.h:108
static int MagickReadDirectory(DIR *directory, struct dirent *entry, struct dirent **result)
Definition: utility-private.h:44
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1123
MagickPrivate void ChopPathComponents(char *, const size_t)
#define MagickPrivate
Definition: method-attribute.h:81