MagickCore 7.0.10
utility-private.h
Go to the documentation of this file.
1/*
2 Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
4
5 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
7
8 http://www.wizard-toolkit.org/script/license.php
9
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 Wizard Toolkit private utility methods.
17*/
18#ifndef _WIZARDSTOOLKIT_UTILITY_PRIVATE_H
19#define _WIZARDSTOOLKIT_UTILITY_PRIVATE_H
20
21#include "wizard/memory_.h"
22#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
23#include "wizard/nt-base.h"
24#endif
25
26#define WizardMax(x,y) (((x) > (y)) ? (x) : (y))
27#define WizardMin(x,y) (((x) < (y)) ? (x) : (y))
28
29#if defined(__cplusplus) || defined(c_plusplus)
30extern "C" {
31#endif
32
33extern WizardExport char
34 **GetPathComponents(const char *,size_t *);
35
37 GetExecutionPath(char *,const size_t);
38
39extern WizardPrivate ssize_t
41
42extern WizardExport void
43 ChopPathComponents(char *,const size_t),
45
46/*
47 Windows UTF8 compatibility methods.
48*/
49
50static inline int access_utf8(const char *path,int mode)
51{
52#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
53 return(access(path,mode));
54#else
55 int
56 count,
57 status;
58
59 WCHAR
60 *path_wide;
61
62 path_wide=(WCHAR *) NULL;
63 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
64 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
65 if (path_wide == (WCHAR *) NULL)
66 return(-1);
67 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
68 status=_waccess(path_wide,mode);
69 path_wide=(WCHAR *) RelinquishWizardMemory(path_wide);
70 return(status);
71#endif
72}
73
74static inline FILE *fopen_utf8(const char *path,const char *mode)
75{
76#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
77 return(fopen(path,mode));
78#else
79 FILE
80 *file;
81
82 int
83 count;
84
85 WCHAR
86 *mode_wide,
87 *path_wide;
88
89 path_wide=(WCHAR *) NULL;
90 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
91 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
92 if (path_wide == (WCHAR *) NULL)
93 return((FILE *) NULL);
94 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
95 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,NULL,0);
96 mode_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*mode_wide));
97 if (mode_wide == (WCHAR *) NULL)
98 {
99 path_wide=(WCHAR *) RelinquishWizardMemory(path_wide);
100 return((FILE *) NULL);
101 }
102 count=MultiByteToWideChar(CP_UTF8,0,mode,-1,mode_wide,count);
103 file=_wfopen(path_wide,mode_wide);
104 mode_wide=(WCHAR *) RelinquishWizardMemory(mode_wide);
105 path_wide=(WCHAR *) RelinquishWizardMemory(path_wide);
106 return(file);
107#endif
108}
109
110#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__)
111typedef int
112 mode_t;
113#endif
114
115static inline int open_utf8(const char *path,int flags,mode_t mode)
116{
117#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
118 return(open(path,flags,mode));
119#else
120 int
121 count,
122 status;
123
124 WCHAR
125 *path_wide;
126
127 path_wide=(WCHAR *) NULL;
128 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
129 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
130 if (path_wide == (WCHAR *) NULL)
131 return(-1);
132 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
133 status=_wopen(path_wide,flags,mode);
134 path_wide=(WCHAR *) RelinquishWizardMemory(path_wide);
135 return(status);
136#endif
137}
138
139static inline FILE *popen_utf8(const char *command,const char *type)
140{
141#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
142 return(popen(command,type));
143#else
144 FILE
145 *file;
146
147 int
148 count;
149
150 WCHAR
151 *type_wide,
152 *command_wide;
153
154 command_wide=(WCHAR *) NULL;
155 count=MultiByteToWideChar(CP_UTF8,0,command,-1,NULL,0);
156 command_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*command_wide));
157 if (command_wide == (WCHAR *) NULL)
158 return((FILE *) NULL);
159 count=MultiByteToWideChar(CP_UTF8,0,command,-1,command_wide,count);
160 count=MultiByteToWideChar(CP_UTF8,0,type,-1,NULL,0);
161 type_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*type_wide));
162 if (type_wide == (WCHAR *) NULL)
163 {
164 command_wide=(WCHAR *) RelinquishWizardMemory(command_wide);
165 return((FILE *) NULL);
166 }
167 count=MultiByteToWideChar(CP_UTF8,0,type,-1,type_wide,count);
168 file=_wpopen(command_wide,type_wide);
169 type_wide=(WCHAR *) RelinquishWizardMemory(type_wide);
170 command_wide=(WCHAR *) RelinquishWizardMemory(command_wide);
171 return(file);
172#endif
173}
174
175static inline int remove_utf8(const char *path)
176{
177#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
178 return(unlink(path));
179#else
180 int
181 count,
182 status;
183
184 WCHAR
185 *path_wide;
186
187 path_wide=(WCHAR *) NULL;
188 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
189 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
190 if (path_wide == (WCHAR *) NULL)
191 return(-1);
192 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
193 status=_wremove(path_wide);
194 path_wide=(WCHAR *) RelinquishWizardMemory(path_wide);
195 return(status);
196#endif
197}
198
199static inline int rename_utf8(const char *source,const char *destination)
200{
201#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
202 return(rename(source,destination));
203#else
204 int
205 count,
206 status;
207
208 WCHAR
209 *destination_wide,
210 *source_wide;
211
212 source_wide=(WCHAR *) NULL;
213 count=MultiByteToWideChar(CP_UTF8,0,source,-1,NULL,0);
214 source_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*source_wide));
215 if (source_wide == (WCHAR *) NULL)
216 return(-1);
217 count=MultiByteToWideChar(CP_UTF8,0,source,-1,source_wide,count);
218 count=MultiByteToWideChar(CP_UTF8,0,destination,-1,NULL,0);
219 destination_wide=(WCHAR *) AcquireQuantumMemory(count,
220 sizeof(*destination_wide));
221 if (destination_wide == (WCHAR *) NULL)
222 {
223 source_wide=(WCHAR *) RelinquishWizardMemory(source_wide);
224 return(-1);
225 }
226 count=MultiByteToWideChar(CP_UTF8,0,destination,-1,destination_wide,count);
227 status=_wrename(source_wide,destination_wide);
228 destination_wide=(WCHAR *) RelinquishWizardMemory(destination_wide);
229 source_wide=(WCHAR *) RelinquishWizardMemory(source_wide);
230 return(status);
231#endif
232}
233
234static inline int stat_utf8(const char *path,struct stat *attributes)
235{
236#if !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
237 return(stat(path,attributes));
238#else
239 int
240 count,
241 status;
242
243 WCHAR
244 *path_wide;
245
246 path_wide=(WCHAR *) NULL;
247 count=MultiByteToWideChar(CP_UTF8,0,path,-1,NULL,0);
248 path_wide=(WCHAR *) AcquireQuantumMemory(count,sizeof(*path_wide));
249 if (path_wide == (WCHAR *) NULL)
250 return(-1);
251 count=MultiByteToWideChar(CP_UTF8,0,path,-1,path_wide,count);
252 status=_wstat64(path_wide,attributes);
253 path_wide=(WCHAR *) RelinquishWizardMemory(path_wide);
254 return(status);
255#endif
256}
257
258#if defined(__cplusplus) || defined(c_plusplus)
259}
260#endif
261
262#endif
WizardExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition memory.c:657
WizardExport void * RelinquishWizardMemory(void *memory)
Definition memory.c:1039
#define WizardPrivate
#define WizardExport
static int open_utf8(const char *path, int flags, mode_t mode)
static FILE * fopen_utf8(const char *path, const char *mode)
WizardExport void ChopPathComponents(char *, const size_t)
WizardPrivate ssize_t GetWizardPageSize(void)
Definition utility.c:817
static int remove_utf8(const char *path)
static int access_utf8(const char *path, int mode)
static int stat_utf8(const char *path, struct stat *attributes)
WizardExport char ** GetPathComponents(const char *, size_t *)
Definition utility.c:576
static int rename_utf8(const char *source, const char *destination)
WizardExport WizardBooleanType GetExecutionPath(char *, const size_t)
Definition utility.c:643
WizardExport void WizardDelay(const WizardSizeType)
Definition utility.c:1042
static FILE * popen_utf8(const char *command, const char *type)
size_t WizardSizeType
Definition wizard-type.h:51
WizardBooleanType
Definition wizard-type.h:26