|
MagickCore
6.7.7
|
00001 /* 00002 Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization 00003 dedicated to making software imaging solutions freely available. 00004 00005 You may not use this file except in compliance with the License. 00006 obtain a copy of the License at 00007 00008 http://www.imagemagick.org/script/license.php 00009 00010 Unless required by applicable law or agreed to in writing, software 00011 distributed under the License is distributed on an "AS IS" BASIS, 00012 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 See the License for the specific language governing permissions and 00014 limitations under the License. 00015 00016 MagickCore private utility methods. 00017 */ 00018 #ifndef _MAGICKCORE_UTILITY_PRIVATE_H 00019 #define _MAGICKCORE_UTILITY_PRIVATE_H 00020 00021 #if defined(__cplusplus) || defined(c_plusplus) 00022 extern "C" { 00023 #endif 00024 00025 #include "MagickCore/memory_.h" 00026 #include "MagickCore/nt-base.h" 00027 #include "MagickCore/nt-base-private.h" 00028 00029 extern MagickPrivate char 00030 **GetPathComponents(const char *,size_t *), 00031 **ListFiles(const char *,const char *,size_t *); 00032 00033 extern MagickPrivate MagickBooleanType 00034 GetExecutionPath(char *,const size_t); 00035 00036 extern MagickPrivate ssize_t 00037 GetMagickPageSize(void); 00038 00039 extern MagickPrivate void 00040 ChopPathComponents(char *,const size_t), 00041 ExpandFilename(char *), 00042 MagickDelay(const MagickSizeType); 00043 00044 /* 00045 Windows UTF8 compatibility methods. 00046 */ 00047 00048 static inline int access_utf8(const char *path,int mode) 00049 { 00050 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 00051 return(access(path,mode)); 00052 #else 00053 int 00054 count, 00055 status; 00056 00057 WCHAR 00058 *path_wide; 00059 00060 path_wide=(WCHAR *) NULL; 00061 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0); 00062 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide)); 00063 if (path_wide == (WCHAR *) NULL) 00064 return(-1); 00065 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count); 00066 status=_waccess(path_wide,mode); 00067 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide); 00068 return(status); 00069 #endif 00070 } 00071 00072 static inline FILE *fopen_utf8(const char *path,const char *mode) 00073 { 00074 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 00075 return(fopen(path,mode)); 00076 #else 00077 FILE 00078 *file; 00079 00080 int 00081 count; 00082 00083 WCHAR 00084 *mode_wide, 00085 *path_wide; 00086 00087 path_wide=(WCHAR *) NULL; 00088 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0); 00089 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide)); 00090 if (path_wide == (WCHAR *) NULL) 00091 return((FILE *) NULL); 00092 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count); 00093 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,NULL,0); 00094 mode_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*mode_wide)); 00095 if (mode_wide == (WCHAR *) NULL) 00096 { 00097 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide); 00098 return((FILE *) NULL); 00099 } 00100 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,mode_wide,count); 00101 file=_wfopen(path_wide,mode_wide); 00102 mode_wide=(WCHAR *) RelinquishMagickMemory(mode_wide); 00103 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide); 00104 return(file); 00105 #endif 00106 } 00107 00108 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__) 00109 typedef int 00110 mode_t; 00111 #endif 00112 00113 static inline int open_utf8(const char *path,int flags,mode_t mode) 00114 { 00115 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 00116 return(open(path,flags,mode)); 00117 #else 00118 int 00119 count, 00120 status; 00121 00122 WCHAR 00123 *path_wide; 00124 00125 path_wide=(WCHAR *) NULL; 00126 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0); 00127 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide)); 00128 if (path_wide == (WCHAR *) NULL) 00129 return(-1); 00130 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count); 00131 status=_wopen(path_wide,flags,mode); 00132 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide); 00133 return(status); 00134 #endif 00135 } 00136 00137 static inline FILE *popen_utf8(const char *command,const char *type) 00138 { 00139 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 00140 return(popen(command,type)); 00141 #else 00142 FILE 00143 *file; 00144 00145 int 00146 count; 00147 00148 WCHAR 00149 *type_wide, 00150 *command_wide; 00151 00152 command_wide=(WCHAR *) NULL; 00153 count=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0); 00154 command_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*command_wide)); 00155 if (command_wide == (WCHAR *) NULL) 00156 return((FILE *) NULL); 00157 count=MultiByteToWideChar(CP_UTF8,0,command,-1,command_wide,count); 00158 count=MultiByteToWideChar(CP_UTF8,0,type,-1,NULL,0); 00159 type_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*type_wide)); 00160 if (type_wide == (WCHAR *) NULL) 00161 { 00162 command_wide=(WCHAR *) RelinquishMagickMemory(command_wide); 00163 return((FILE *) NULL); 00164 } 00165 count=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,count); 00166 file=_wpopen(command_wide,type_wide); 00167 type_wide=(WCHAR *) RelinquishMagickMemory(type_wide); 00168 command_wide=(WCHAR *) RelinquishMagickMemory(command_wide); 00169 return(file); 00170 #endif 00171 } 00172 00173 static inline int remove_utf8(const char *path) 00174 { 00175 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 00176 return(unlink(path)); 00177 #else 00178 int 00179 count, 00180 status; 00181 00182 WCHAR 00183 *path_wide; 00184 00185 path_wide=(WCHAR *) NULL; 00186 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0); 00187 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide)); 00188 if (path_wide == (WCHAR *) NULL) 00189 return(-1); 00190 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count); 00191 status=_wremove(path_wide); 00192 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide); 00193 return(status); 00194 #endif 00195 } 00196 00197 static inline int rename_utf8(const char *source,const char *destination) 00198 { 00199 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 00200 return(rename(source,destination)); 00201 #else 00202 int 00203 count, 00204 status; 00205 00206 WCHAR 00207 *destination_wide, 00208 *source_wide; 00209 00210 source_wide=(WCHAR *) NULL; 00211 count=MultiByteToWideChar(CP_UTF8,0,source,-1,NULL,0); 00212 source_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*source_wide)); 00213 if (source_wide == (WCHAR *) NULL) 00214 return(-1); 00215 count=MultiByteToWideChar(CP_UTF8,0,source,-1,source_wide,count); 00216 count=MultiByteToWideChar(CP_UTF8,0,destination,-1,NULL,0); 00217 destination_wide=(WCHAR *) AcquireQuantumMemory(count, 00218 sizeof(*destination_wide)); 00219 if (destination_wide == (WCHAR *) NULL) 00220 { 00221 source_wide=(WCHAR *) RelinquishMagickMemory(source_wide); 00222 return(-1); 00223 } 00224 count=MultiByteToWideChar(CP_UTF8,0,destination,-1,destination_wide,count); 00225 status=_wrename(source_wide,destination_wide); 00226 destination_wide=(WCHAR *) RelinquishMagickMemory(destination_wide); 00227 source_wide=(WCHAR *) RelinquishMagickMemory(source_wide); 00228 return(status); 00229 #endif 00230 } 00231 00232 static inline int stat_utf8(const char *path,struct stat *attributes) 00233 { 00234 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) 00235 return(stat(path,attributes)); 00236 #else 00237 int 00238 count, 00239 status; 00240 00241 WCHAR 00242 *path_wide; 00243 00244 path_wide=(WCHAR *) NULL; 00245 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0); 00246 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide)); 00247 if (path_wide == (WCHAR *) NULL) 00248 return(-1); 00249 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count); 00250 status=_wstat64(path_wide,attributes); 00251 path_wide=(WCHAR *) RelinquishMagickMemory(path_wide); 00252 return(status); 00253 #endif 00254 } 00255 00256 #if defined(__cplusplus) || defined(c_plusplus) 00257 } 00258 #endif 00259 00260 #endif