cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization |
| 3 | dedicated to making software imaging solutions freely available. |
cristy | 99d6fa0 | 2011-09-23 13:09:30 +0000 | [diff] [blame] | 4 | |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 5 | You may not use this file except in compliance with the License. |
| 6 | obtain a copy of the License at |
cristy | 99d6fa0 | 2011-09-23 13:09:30 +0000 | [diff] [blame] | 7 | |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 8 | http://www.imagemagick.org/script/license.php |
cristy | 99d6fa0 | 2011-09-23 13:09:30 +0000 | [diff] [blame] | 9 | |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 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. |
| 15 | |
| 16 | MagickCore private utility methods. |
| 17 | */ |
| 18 | #ifndef _MAGICKCORE_UTILITY_PRIVATE_H |
| 19 | #define _MAGICKCORE_UTILITY_PRIVATE_H |
| 20 | |
| 21 | #if defined(__cplusplus) || defined(c_plusplus) |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | extern MagickPrivate char |
| 26 | **GetPathComponents(const char *,size_t *), |
| 27 | **ListFiles(const char *,const char *,size_t *); |
| 28 | |
| 29 | extern MagickPrivate MagickBooleanType |
| 30 | GetExecutionPath(char *,const size_t); |
| 31 | |
| 32 | extern MagickPrivate ssize_t |
| 33 | GetMagickPageSize(void); |
| 34 | |
| 35 | extern MagickPrivate void |
| 36 | ChopPathComponents(char *,const size_t), |
| 37 | ExpandFilename(char *), |
| 38 | MagickDelay(const MagickSizeType); |
| 39 | |
cristy | 99d6fa0 | 2011-09-23 13:09:30 +0000 | [diff] [blame] | 40 | /* |
| 41 | Windows UTF8 compatibility methods. |
| 42 | */ |
| 43 | |
| 44 | static inline int access_utf8(const char *path,int mode) |
| 45 | { |
| 46 | #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) |
| 47 | return(access(path,mode)); |
| 48 | #else |
| 49 | int |
| 50 | count, |
| 51 | status; |
| 52 | |
| 53 | WCHAR |
| 54 | *path_wide; |
| 55 | |
| 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) |
| 60 | return(-1); |
| 61 | count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count); |
| 62 | status=_waccess(path_wide,mode); |
| 63 | path_wide=RelinquishMagickMemory(path_wide); |
| 64 | return(status); |
| 65 | #endif |
| 66 | } |
| 67 | |
| 68 | static inline FILE *fopen_utf8(const char *path,const char *mode) |
| 69 | { |
| 70 | #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) |
| 71 | return(fopen(path,mode)); |
| 72 | #else |
| 73 | FILE |
| 74 | *file; |
| 75 | |
| 76 | int |
| 77 | status; |
| 78 | |
| 79 | WCHAR |
| 80 | *mode_wide, |
| 81 | *path_wide; |
| 82 | |
| 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(-1); |
| 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) |
| 92 | { |
| 93 | path_wide=RelinquishMagickMemory(path_wide); |
| 94 | return(-1); |
| 95 | } |
| 96 | count=MultiByteToWideChar(CP_UTF8,0,mode,-1,mode_wide,count); |
| 97 | file=_wfopen(path_wide,mode_width); |
| 98 | mode_wide=RelinquishMagickMemory(mode_wide); |
| 99 | path_wide=RelinquishMagickMemory(path_wide); |
| 100 | return(file); |
| 101 | #endif |
| 102 | } |
| 103 | |
| 104 | static inline int open_utf8(const char *path,int flags,int mode) |
| 105 | { |
| 106 | #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) |
| 107 | return(open(path,flags,mode)); |
| 108 | #else |
| 109 | int |
| 110 | count, |
| 111 | status; |
| 112 | |
| 113 | WCHAR |
| 114 | *path_wide; |
| 115 | |
| 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) |
| 120 | return(-1); |
| 121 | count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count); |
| 122 | status=_wopen(path_wide,flags,mode); |
| 123 | path_wide=RelinquishMagickMemory(path_wide); |
| 124 | return(status); |
| 125 | #endif |
| 126 | } |
| 127 | |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame^] | 128 | static inline FILE *popen_utf8(const char *command,const char *type) |
| 129 | { |
| 130 | #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) |
| 131 | return(fopen(command,type)); |
| 132 | #else |
| 133 | FILE |
| 134 | *file; |
| 135 | |
| 136 | int |
| 137 | status; |
| 138 | |
| 139 | WCHAR |
| 140 | *type_wide, |
| 141 | *command_wide; |
| 142 | |
| 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(-1); |
| 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) |
| 152 | { |
| 153 | command_wide=RelinquishMagickMemory(command_wide); |
| 154 | return(-1); |
| 155 | } |
| 156 | count=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,count); |
| 157 | file=_wpopen(path_wide,type_width); |
| 158 | type_wide=RelinquishMagickMemory(type_wide); |
| 159 | path_wide=RelinquishMagickMemory(path_wide); |
| 160 | return(file); |
| 161 | #endif |
| 162 | } |
| 163 | |
cristy | 99d6fa0 | 2011-09-23 13:09:30 +0000 | [diff] [blame] | 164 | static inline int remove_utf8(const char *path) |
| 165 | { |
| 166 | #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) |
| 167 | return(unlink(path)); |
| 168 | #else |
| 169 | int |
| 170 | count, |
| 171 | status; |
| 172 | |
| 173 | WCHAR |
| 174 | *path_wide; |
| 175 | |
| 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) |
| 180 | return(-1); |
| 181 | count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count); |
| 182 | status=_wremove(path_wide); |
| 183 | path_wide=RelinquishMagickMemory(path_wide); |
| 184 | return(status); |
| 185 | #endif |
| 186 | } |
| 187 | |
| 188 | static inline int stat_utf8(const char *path,struct stat *attributes) |
| 189 | { |
| 190 | #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) |
| 191 | return(stat(path,attributes)); |
| 192 | #else |
| 193 | int |
| 194 | count, |
| 195 | status; |
| 196 | |
| 197 | WCHAR |
| 198 | *path_wide; |
| 199 | |
| 200 | path_wide=(WCHAR *) NULL; |
| 201 | count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0); |
| 202 | path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide)); |
| 203 | if (path_wide == (WCHAR *) NULL) |
| 204 | return(-1); |
| 205 | count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count); |
| 206 | status=_wstat(path_wide,attributes); |
| 207 | path_wide=RelinquishMagickMemory(path_wide); |
| 208 | return(status); |
| 209 | #endif |
| 210 | } |
| 211 | |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 212 | #if defined(__cplusplus) || defined(c_plusplus) |
| 213 | } |
| 214 | #endif |
| 215 | |
| 216 | #endif |