2 Copyright 1999-2011 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 extern MagickPrivate char
26 **GetPathComponents(const char *,size_t *),
27 **ListFiles(const char *,const char *,size_t *);
29 extern MagickPrivate MagickBooleanType
30 GetExecutionPath(char *,const size_t);
32 extern MagickPrivate ssize_t
33 GetMagickPageSize(void);
35 extern MagickPrivate void
36 ChopPathComponents(char *,const size_t),
37 ExpandFilename(char *),
38 MagickDelay(const MagickSizeType);
41 Windows UTF8 compatibility methods.
44 static inline int access_utf8(const char *path,int mode)
46 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
47 return(access(path,mode));
56 path_wide=(WCHAR *) NULL;
57 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
58 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
59 if (path_wide == (WCHAR *) NULL)
61 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
62 status=_waccess(path_wide,mode);
63 path_wide=RelinquishMagickMemory(path_wide);
68 static inline FILE *fopen_utf8(const char *path,const char *mode)
70 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
71 return(fopen(path,mode));
83 path_wide=(WCHAR *) NULL;
84 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
85 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
86 if (path_wide == (WCHAR *) NULL)
87 return((FILE *) NULL);
88 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
89 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,NULL,0);
90 mode_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*mode_wide));
91 if (mode_wide == (WCHAR *) NULL)
93 path_wide=RelinquishMagickMemory(path_wide);
94 return((FILE *) NULL);
96 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,mode_wide,count);
97 file=_wfopen(path_wide,mode_wide);
98 mode_wide=RelinquishMagickMemory(mode_wide);
99 path_wide=RelinquishMagickMemory(path_wide);
104 static inline int open_utf8(const char *path,int flags,int mode)
106 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
107 return(open(path,flags,mode));
116 path_wide=(WCHAR *) NULL;
117 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
118 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
119 if (path_wide == (WCHAR *) NULL)
121 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
122 status=_wopen(path_wide,flags,mode);
123 path_wide=RelinquishMagickMemory(path_wide);
128 static inline FILE *popen_utf8(const char *command,const char *type)
130 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
131 return(fopen(command,type));
143 command_wide=(WCHAR *) NULL;
144 count=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0);
145 command_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*command_wide));
146 if (command_wide == (WCHAR *) NULL)
147 return((FILE *) NULL);
148 count=MultiByteToWideChar(CP_UTF8,0,command,-1,command_wide,count);
149 count=MultiByteToWideChar(CP_UTF8,0,type,-1,NULL,0);
150 type_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*type_wide));
151 if (type_wide == (WCHAR *) NULL)
153 command_wide=RelinquishMagickMemory(command_wide);
154 return((FILE *) NULL);
156 count=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,count);
157 file=_wpopen(command_wide,type_wide);
158 type_wide=RelinquishMagickMemory(type_wide);
159 command_wide=RelinquishMagickMemory(command_wide);
164 static inline int remove_utf8(const char *path)
166 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
167 return(unlink(path));
176 path_wide=(WCHAR *) NULL;
177 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
178 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
179 if (path_wide == (WCHAR *) NULL)
181 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
182 status=_wremove(path_wide);
183 path_wide=RelinquishMagickMemory(path_wide);
188 static inline int rename_utf8(const char *source,const char *destination)
190 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
191 return(rename(source,destination));
201 source_wide=(WCHAR *) NULL;
202 count=MultiByteToWideChar(CP_UTF8,0,source,-1,NULL,0);
203 source_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*source_wide));
204 if (source_wide == (WCHAR *) NULL)
206 count=MultiByteToWideChar(CP_UTF8,0,source,-1,source_wide,count);
207 count=MultiByteToWideChar(CP_UTF8,0,destination,-1,NULL,0);
208 destination_wide=(WCHAR *) AcquireQuantumMemory(count,
209 sizeof(*destination_wide));
210 if (destination_wide == (WCHAR *) NULL)
212 source_wide=RelinquishMagickMemory(source_wide);
215 count=MultiByteToWideChar(CP_UTF8,0,destination,-1,destination_wide,count);
216 status=_wrename(source_wide,destination_wide);
217 destination_wide=RelinquishMagickMemory(destination_wide);
218 source_wide=RelinquishMagickMemory(source_wide);
223 static inline int stat_utf8(const char *path,struct stat *attributes)
225 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
226 return(stat(path,attributes));
235 path_wide=(WCHAR *) NULL;
236 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
237 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
238 if (path_wide == (WCHAR *) NULL)
240 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
241 status=wstat(path_wide,attributes);
242 path_wide=RelinquishMagickMemory(path_wide);
247 #if defined(__cplusplus) || defined(c_plusplus)