2 Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
5 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
8 http://www.imagemagick.org/script/license.php
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
16 MagickCore private utility methods.
18 #ifndef _MAGICKCORE_UTILITY_PRIVATE_H
19 #define _MAGICKCORE_UTILITY_PRIVATE_H
21 #if defined(__cplusplus) || defined(c_plusplus)
25 #include "MagickCore/memory_.h"
26 #include "MagickCore/nt-base.h"
27 #include "MagickCore/nt-base-private.h"
29 extern MagickPrivate char
30 **GetPathComponents(const char *,size_t *),
31 **ListFiles(const char *,const char *,size_t *);
33 extern MagickPrivate MagickBooleanType
34 GetExecutionPath(char *,const size_t);
36 extern MagickPrivate ssize_t
37 GetMagickPageSize(void);
39 extern MagickPrivate void
40 ChopPathComponents(char *,const size_t),
41 ExpandFilename(char *),
42 MagickDelay(const MagickSizeType);
45 Windows UTF8 compatibility methods.
48 static inline int access_utf8(const char *path,int mode)
50 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
51 return(access(path,mode));
60 path_wide=(WCHAR *) NULL;
61 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
62 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
63 if (path_wide == (WCHAR *) NULL)
65 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
66 status=_waccess(path_wide,mode);
67 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
72 static inline FILE *fopen_utf8(const char *path,const char *mode)
74 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
75 return(fopen(path,mode));
87 path_wide=(WCHAR *) NULL;
88 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
89 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
90 if (path_wide == (WCHAR *) NULL)
91 return((FILE *) NULL);
92 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
93 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,NULL,0);
94 mode_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*mode_wide));
95 if (mode_wide == (WCHAR *) NULL)
97 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
98 return((FILE *) NULL);
100 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,mode_wide,count);
101 file=_wfopen(path_wide,mode_wide);
102 mode_wide=(WCHAR *) RelinquishMagickMemory(mode_wide);
103 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
108 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__)
113 static inline int open_utf8(const char *path,int flags,mode_t mode)
115 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
116 return(open(path,flags,mode));
125 path_wide=(WCHAR *) NULL;
126 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
127 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
128 if (path_wide == (WCHAR *) NULL)
130 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
131 status=_wopen(path_wide,flags,mode);
132 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
137 static inline FILE *popen_utf8(const char *command,const char *type)
139 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
140 return(popen(command,type));
152 command_wide=(WCHAR *) NULL;
153 count=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0);
154 command_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*command_wide));
155 if (command_wide == (WCHAR *) NULL)
156 return((FILE *) NULL);
157 count=MultiByteToWideChar(CP_UTF8,0,command,-1,command_wide,count);
158 count=MultiByteToWideChar(CP_UTF8,0,type,-1,NULL,0);
159 type_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*type_wide));
160 if (type_wide == (WCHAR *) NULL)
162 command_wide=(WCHAR *) RelinquishMagickMemory(command_wide);
163 return((FILE *) NULL);
165 count=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,count);
166 file=_wpopen(command_wide,type_wide);
167 type_wide=(WCHAR *) RelinquishMagickMemory(type_wide);
168 command_wide=(WCHAR *) RelinquishMagickMemory(command_wide);
173 static inline int remove_utf8(const char *path)
175 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
176 return(unlink(path));
185 path_wide=(WCHAR *) NULL;
186 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
187 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
188 if (path_wide == (WCHAR *) NULL)
190 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
191 status=_wremove(path_wide);
192 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
197 static inline int rename_utf8(const char *source,const char *destination)
199 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
200 return(rename(source,destination));
210 source_wide=(WCHAR *) NULL;
211 count=MultiByteToWideChar(CP_UTF8,0,source,-1,NULL,0);
212 source_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*source_wide));
213 if (source_wide == (WCHAR *) NULL)
215 count=MultiByteToWideChar(CP_UTF8,0,source,-1,source_wide,count);
216 count=MultiByteToWideChar(CP_UTF8,0,destination,-1,NULL,0);
217 destination_wide=(WCHAR *) AcquireQuantumMemory(count,
218 sizeof(*destination_wide));
219 if (destination_wide == (WCHAR *) NULL)
221 source_wide=(WCHAR *) RelinquishMagickMemory(source_wide);
224 count=MultiByteToWideChar(CP_UTF8,0,destination,-1,destination_wide,count);
225 status=_wrename(source_wide,destination_wide);
226 destination_wide=(WCHAR *) RelinquishMagickMemory(destination_wide);
227 source_wide=(WCHAR *) RelinquishMagickMemory(source_wide);
232 static inline int stat_utf8(const char *path,struct stat *attributes)
234 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
235 return(stat(path,attributes));
244 path_wide=(WCHAR *) NULL;
245 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
246 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
247 if (path_wide == (WCHAR *) NULL)
249 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
250 status=_wstat64(path_wide,attributes);
251 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
256 #if defined(__cplusplus) || defined(c_plusplus)