2 Copyright 1999-2014 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 #include "MagickCore/memory_.h"
22 #include "MagickCore/nt-base.h"
23 #include "MagickCore/nt-base-private.h"
25 #if defined(__cplusplus) || defined(c_plusplus)
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),
35 ShredFile(const char *);
37 extern MagickPrivate ssize_t
38 GetMagickPageSize(void);
40 extern MagickPrivate void
41 ChopPathComponents(char *,const size_t),
42 ExpandFilename(char *),
43 MagickDelay(const MagickSizeType);
46 Windows UTF8 compatibility methods.
49 static inline int access_utf8(const char *path,int mode)
51 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
52 return(access(path,mode));
61 path_wide=(WCHAR *) NULL;
62 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
63 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
64 if (path_wide == (WCHAR *) NULL)
66 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
67 status=_waccess(path_wide,mode);
68 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
73 static inline FILE *fopen_utf8(const char *path,const char *mode)
75 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
76 return(fopen(path,mode));
88 path_wide=(WCHAR *) NULL;
89 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
90 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
91 if (path_wide == (WCHAR *) NULL)
92 return((FILE *) NULL);
93 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
94 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,NULL,0);
95 mode_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*mode_wide));
96 if (mode_wide == (WCHAR *) NULL)
98 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
99 return((FILE *) NULL);
101 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,mode_wide,count);
102 file=_wfopen(path_wide,mode_wide);
103 mode_wide=(WCHAR *) RelinquishMagickMemory(mode_wide);
104 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
109 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__)
114 static inline int open_utf8(const char *path,int flags,mode_t mode)
116 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
117 return(open(path,flags,mode));
126 path_wide=(WCHAR *) NULL;
127 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
128 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
129 if (path_wide == (WCHAR *) NULL)
131 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
132 status=_wopen(path_wide,flags,mode);
133 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
138 static inline FILE *popen_utf8(const char *command,const char *type)
140 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
141 return(popen(command,type));
153 command_wide=(WCHAR *) NULL;
154 count=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0);
155 command_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*command_wide));
156 if (command_wide == (WCHAR *) NULL)
157 return((FILE *) NULL);
158 count=MultiByteToWideChar(CP_UTF8,0,command,-1,command_wide,count);
159 count=MultiByteToWideChar(CP_UTF8,0,type,-1,NULL,0);
160 type_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*type_wide));
161 if (type_wide == (WCHAR *) NULL)
163 command_wide=(WCHAR *) RelinquishMagickMemory(command_wide);
164 return((FILE *) NULL);
166 count=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,count);
167 file=_wpopen(command_wide,type_wide);
168 type_wide=(WCHAR *) RelinquishMagickMemory(type_wide);
169 command_wide=(WCHAR *) RelinquishMagickMemory(command_wide);
174 static inline int remove_utf8(const char *path)
176 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
177 return(unlink(path));
186 path_wide=(WCHAR *) NULL;
187 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
188 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
189 if (path_wide == (WCHAR *) NULL)
191 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
192 status=_wremove(path_wide);
193 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
198 static inline int rename_utf8(const char *source,const char *destination)
200 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
201 return(rename(source,destination));
211 source_wide=(WCHAR *) NULL;
212 count=MultiByteToWideChar(CP_UTF8,0,source,-1,NULL,0);
213 source_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*source_wide));
214 if (source_wide == (WCHAR *) NULL)
216 count=MultiByteToWideChar(CP_UTF8,0,source,-1,source_wide,count);
217 count=MultiByteToWideChar(CP_UTF8,0,destination,-1,NULL,0);
218 destination_wide=(WCHAR *) AcquireQuantumMemory(count,
219 sizeof(*destination_wide));
220 if (destination_wide == (WCHAR *) NULL)
222 source_wide=(WCHAR *) RelinquishMagickMemory(source_wide);
225 count=MultiByteToWideChar(CP_UTF8,0,destination,-1,destination_wide,count);
226 status=_wrename(source_wide,destination_wide);
227 destination_wide=(WCHAR *) RelinquishMagickMemory(destination_wide);
228 source_wide=(WCHAR *) RelinquishMagickMemory(source_wide);
233 static inline int stat_utf8(const char *path,struct stat *attributes)
235 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
236 return(stat(path,attributes));
245 path_wide=(WCHAR *) NULL;
246 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
247 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
248 if (path_wide == (WCHAR *) NULL)
250 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
251 status=wstat(path_wide,attributes);
252 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide);
257 #if defined(__cplusplus) || defined(c_plusplus)