18 #ifndef MAGICKCORE_UTILITY_PRIVATE_H
19 #define MAGICKCORE_UTILITY_PRIVATE_H
25 #if defined(__cplusplus) || defined(c_plusplus)
45 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
46 static inline wchar_t *create_wchar_path(
const char *utf8)
54 count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,NULL,0);
55 if ((count > MAX_PATH) && (NTLongPathsEnabled() ==
MagickFalse))
67 if (longPath == (
wchar_t *) NULL)
68 return((
wchar_t *) NULL);
69 count=MultiByteToWideChar(CP_UTF8,0,buffer,-1,longPath,count);
71 count=GetShortPathNameW(longPath,shortPath,MAX_PATH);
73 if ((count < 5) || (count >= MAX_PATH))
74 return((
wchar_t *) NULL);
76 wcscpy(wideChar,shortPath+4);
80 if (wideChar == (
wchar_t *) NULL)
81 return((
wchar_t *) NULL);
82 count=MultiByteToWideChar(CP_UTF8,0,utf8,-1,wideChar,count);
86 return((
wchar_t *) NULL);
94 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
95 return(access(
path,mode));
103 path_wide=create_wchar_path(
path);
104 if (path_wide == (
wchar_t *) NULL)
106 status=_waccess(path_wide,mode);
114 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
115 return(fopen(
path,mode));
124 path_wide=create_wchar_path(
path);
125 if (path_wide == (
wchar_t *) NULL)
126 return((FILE *) NULL);
127 mode_wide=create_wchar_path(mode);
128 if (mode_wide == (
wchar_t *) NULL)
131 return((FILE *) NULL);
133 file=_wfopen(path_wide,mode_wide);
142 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
146 directory=getcwd(
path,extent);
153 (void) WideCharToMultiByte(CP_UTF8,0,wide_path,-1,
path,(
int) extent,NULL,NULL);
157 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__)
164 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
165 return(open(
path,flags,mode));
173 path_wide=create_wchar_path(
path);
174 if (path_wide == (
wchar_t *) NULL)
176 status=_wopen(path_wide,flags,mode);
182 static inline FILE *
popen_utf8(
const char *command,
const char *type)
184 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
185 return(popen(command,type));
198 length=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,5);
201 length=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0);
205 if (command_wide == (
wchar_t *) NULL)
207 length=MultiByteToWideChar(CP_UTF8,0,command,-1,command_wide,length);
209 file=_wpopen(command_wide,type_wide);
217 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
218 return(unlink(
path));
226 path_wide=create_wchar_path(
path);
227 if (path_wide == (
wchar_t *) NULL)
229 status=_wremove(path_wide);
235 static inline int rename_utf8(
const char *source,
const char *destination)
237 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
238 return(rename(source,destination));
247 source_wide=create_wchar_path(source);
248 if (source_wide == (
wchar_t *) NULL)
250 destination_wide=create_wchar_path(destination);
251 if (destination_wide == (
wchar_t *) NULL)
256 status=_wrename(source_wide,destination_wide);
265 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__)
266 return(stat(
path,attributes));
274 path_wide=create_wchar_path(
path);
275 if (path_wide == (WCHAR *) NULL)
277 status=wstat(path_wide,attributes);
283 #if defined(__cplusplus) || defined(c_plusplus)