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-private.h"
28 extern MagickPrivate char
29 **GetPathComponents(const char *,size_t *),
30 **ListFiles(const char *,const char *,size_t *);
32 extern MagickPrivate MagickBooleanType
33 GetExecutionPath(char *,const size_t);
35 extern MagickPrivate ssize_t
36 GetMagickPageSize(void);
38 extern MagickPrivate void
39 ChopPathComponents(char *,const size_t),
40 ExpandFilename(char *),
41 MagickDelay(const MagickSizeType);
44 Windows UTF8 compatibility methods.
47 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__)
51 static inline int MultiByteToWideCharacter(const char *string,
52 WCHAR **wide_string,size_t *extent)
58 if (wide_string == (WCHAR **) NULL)
60 *wide_string=(WCHAR *) NULL;
61 if (string == (const char *) NULL)
63 length=strlen(string)+1;
64 *wide_string=(WCHAR *) AcquireQuantumMemory(length,sizeof(*wide_string));
65 if (*wide_string == (WCHAR *) NULL)
67 return(mbstowcs_s(extent,*wide_string,length,string,_TRUNCATE));
71 static inline int access_utf8(const char *path,int mode)
73 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
74 return(access(path,mode));
85 status=MultiByteToWideCharacter(path,&wide_path,&extent);
88 status=_waccess(wide_path,mode);
89 wide_path=(WCHAR *) RelinquishMagickMemory(wide_path);
94 static inline FILE *fopen_utf8(const char *path,const char *mode)
96 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
97 return(fopen(path,mode));
112 status=MultiByteToWideCharacter(path,&wide_path,&extent);
114 return((FILE *) NULL);
115 status=MultiByteToWideCharacter(mode,&wide_mode,&extent);
118 wide_path=(WCHAR *) RelinquishMagickMemory(wide_path);
119 return((FILE *) NULL);
121 file=_wfopen(wide_path,wide_mode);
122 wide_mode=(WCHAR *) RelinquishMagickMemory(wide_mode);
123 wide_path=(WCHAR *) RelinquishMagickMemory(wide_path);
128 static inline int open_utf8(const char *path,int flags,mode_t mode)
130 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
131 return(open(path,flags,mode));
142 status=MultiByteToWideCharacter(path,&wide_path,&extent);
145 status=_wopen(wide_path,flags,mode);
146 wide_path=(WCHAR *) RelinquishMagickMemory(wide_path);
151 static inline FILE *popen_utf8(const char *command,const char *type)
153 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
154 return(fopen(command,type));
169 status=MultiByteToWideCharacter(command,&wide_command,&extent);
171 return((FILE *) NULL);
172 status=MultiByteToWideCharacter(type,&wide_type,&extent);
175 wide_command=(WCHAR *) RelinquishMagickMemory(wide_command);
176 return((FILE *) NULL);
178 file=_wpopen(wide_command,wide_type);
179 wide_type=(WCHAR *) RelinquishMagickMemory(wide_type);
180 wide_command=(WCHAR *) RelinquishMagickMemory(wide_command);
185 static inline int remove_utf8(const char *path)
187 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
188 return(unlink(path));
199 status=MultiByteToWideCharacter(path,&wide_path,&extent);
202 status=_wremove(wide_path);
203 wide_path=(WCHAR *) RelinquishMagickMemory(wide_path);
208 static inline int rename_utf8(const char *source,const char *destination)
210 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
211 return(rename(source,destination));
223 status=MultiByteToWideCharacter(source,&wide_source,&extent);
226 status=MultiByteToWideCharacter(destination,&wide_destination,&extent);
229 wide_source=(WCHAR *) RelinquishMagickMemory(wide_source);
232 status=_wrename(wide_source,wide_destination);
233 wide_destination=(WCHAR *) RelinquishMagickMemory(wide_destination);
234 wide_source=(WCHAR *) RelinquishMagickMemory(wide_source);
239 static inline int stat_utf8(const char *path,struct stat *attributes)
241 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
242 return(stat(path,attributes));
253 status=MultiByteToWideCharacter(path,&wide_path,&extent);
256 status=_wstat64(wide_path,attributes);
257 wide_path=(WCHAR *) RelinquishMagickMemory(wide_path);
262 #if defined(__cplusplus) || defined(c_plusplus)