1 /*
2   Copyright 1999-2021 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.  You may
6   obtain a copy of the License at
7 
8     https://imagemagick.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   MagickCore private application programming interface declarations.
17 */
18 #ifndef MAGICKCORE_STUDIO_H
19 #define MAGICKCORE_STUDIO_H
20 
21 #if defined(__cplusplus) || defined(c_plusplus)
22 extern "C" {
23 #endif
24 
25 #if defined(WIN32) || defined(WIN64)
26 #  define MAGICKCORE_WINDOWS_SUPPORT
27 #else
28 #  define MAGICKCORE_POSIX_SUPPORT
29 #endif
30 
31 #define MAGICKCORE_IMPLEMENTATION  1
32 
33 #if !defined(MAGICKCORE_CONFIG_H)
34 # define MAGICKCORE_CONFIG_H
35 #include "MagickCore/magick-config.h"
36 # if defined(MAGICKCORE__FILE_OFFSET_BITS) && !defined(_FILE_OFFSET_BITS)
37 # define _FILE_OFFSET_BITS MAGICKCORE__FILE_OFFSET_BITS
38 #endif
39 #if defined(_magickcore_const) && !defined(const)
40 # define const  _magickcore_const
41 #endif
42 #if defined(_magickcore_inline) && !defined(inline)
43 # define inline  _magickcore_inline
44 #endif
45 # if defined(__cplusplus) || defined(c_plusplus)
46 #  undef inline
47 # endif
48 #endif
49 
50 #if defined(MAGICKCORE_NAMESPACE_PREFIX)
51 # include "MagickCore/methods.h"
52 #endif
53 
54 #if !defined(const)
55 #  define STDC
56 #endif
57 
58 #include <stdarg.h>
59 #include <stdio.h>
60 #if defined(MAGICKCORE_HAVE_SYS_STAT_H)
61 # include <sys/stat.h>
62 #endif
63 #if defined(MAGICKCORE_STDC_HEADERS)
64 # include <stdlib.h>
65 # include <stddef.h>
66 #else
67 # if defined(MAGICKCORE_HAVE_STDLIB_H)
68 #  include <stdlib.h>
69 # endif
70 #endif
71 #if !defined(magick_restrict)
72 # if !defined(_magickcore_restrict)
73 #  define magick_restrict restrict
74 # else
75 #  define magick_restrict _magickcore_restrict
76 # endif
77 #endif
78 #if defined(MAGICKCORE_HAVE_STRING_H)
79 # if !defined(STDC_HEADERS) && defined(MAGICKCORE_HAVE_MEMORY_H)
80 #  include <memory.h>
81 # endif
82 # include <string.h>
83 #endif
84 #if defined(MAGICKCORE_HAVE_STRINGS_H)
85 # include <strings.h>
86 #endif
87 #if defined(MAGICKCORE_HAVE_INTTYPES_H)
88 # include <inttypes.h>
89 #endif
90 #if defined(MAGICKCORE_HAVE_STDINT_H)
91 # include <stdint.h>
92 #endif
93 #if defined(MAGICKCORE_HAVE_UNISTD_H)
94 # include <unistd.h>
95 #endif
96 #if defined(MAGICKCORE_WINDOWS_SUPPORT) && defined(_DEBUG)
97 #define _CRTDBG_MAP_ALLOC
98 #endif
99 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
100 # include <io.h>
101 #if !defined(__CYGWIN__)
102 # include <direct.h>
103 #endif
104 # if !defined(MAGICKCORE_HAVE_STRERROR)
105 #  define HAVE_STRERROR
106 # endif
107 #endif
108 
109 #include <ctype.h>
110 #include <locale.h>
111 #include <errno.h>
112 #include <fcntl.h>
113 #include <math.h>
114 #include <time.h>
115 #include <limits.h>
116 #include <signal.h>
117 #include <assert.h>
118 
119 #if defined(MAGICKCORE_HAVE_XLOCALE_H)
120 # include <xlocale.h>
121 #endif
122 #if defined(MAGICKCORE_THREAD_SUPPORT)
123 # include <pthread.h>
124 #endif
125 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
126 #if !defined(__CYGWIN__)
127 #include <winsock2.h>
128 #include <ws2tcpip.h>
129 #endif
130 #include <windows.h>
131 #ifdef _MSC_VER
132 #pragma comment (lib, "ws2_32.lib")
133 #endif
134 #endif
135 #if defined(MAGICKCORE_HAVE_SYS_SYSLIMITS_H)
136 # include <sys/syslimits.h>
137 #endif
138 #if defined(MAGICKCORE_HAVE_ARM_LIMITS_H)
139 # include <arm/limits.h>
140 #endif
141 
142 #if defined(MAGICKCORE_HAVE_CL_CL_H)
143 #  include <CL/cl.h>
144 #  define MAGICKCORE_OPENCL_SUPPORT  1
145 #endif
146 #if defined(MAGICKCORE_HAVE_OPENCL_CL_H)
147 #  include <OpenCL/cl.h>
148 #  define MAGICKCORE_OPENCL_SUPPORT  1
149 #endif
150 
151 #if defined(_OPENMP) && ((_OPENMP >= 200203) || defined(__OPENCC__))
152 #  include <omp.h>
153 #  define MAGICKCORE_OPENMP_SUPPORT  1
154 #endif
155 
156 #if defined(MAGICKCORE_HAVE_PREAD) && defined(MAGICKCORE_HAVE_DECL_PREAD) && !MAGICKCORE_HAVE_DECL_PREAD
157 ssize_t pread(int,void *,size_t,off_t);
158 #endif
159 
160 #if defined(MAGICKCORE_HAVE_PWRITE) && defined(MAGICKCORE_HAVE_DECL_PWRITE) && !MAGICKCORE_HAVE_DECL_PWRITE
161 ssize_t pwrite(int,const void *,size_t,off_t);
162 #endif
163 
164 #if defined(MAGICKCORE_HAVE_STRLCPY) && defined(MAGICKCORE_HAVE_DECL_STRLCPY) && !MAGICKCORE_HAVE_DECL_STRLCPY
165 extern size_t strlcpy(char *,const char *,size_t);
166 #endif
167 
168 #if defined(MAGICKCORE_HAVE_VSNPRINTF) && defined(MAGICKCORE_HAVE_DECL_VSNPRINTF) && !MAGICKCORE_HAVE_DECL_VSNPRINTF
169 extern int vsnprintf(char *,size_t,const char *,va_list);
170 #endif
171 
172 #include "MagickCore/method-attribute.h"
173 
174 #if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(MAGICKCORE_POSIX_SUPPORT)
175 # include <sys/types.h>
176 # include <sys/stat.h>
177 # if defined(MAGICKCORE_POSIX_SUPPORT)
178 #  if defined(MAGICKCORE_HAVE_SYS_NDIR_H) || defined(MAGICKCORE_HAVE_SYS_DIR_H) || defined(MAGICKCORE_HAVE_NDIR_H)
179 #   define dirent direct
180 #   define NAMLEN(dirent) (dirent)->d_namlen
181 #   if defined(MAGICKCORE_HAVE_SYS_NDIR_H)
182 #    include <sys/ndir.h>
183 #   endif
184 #   if defined(MAGICKCORE_HAVE_SYS_DIR_H)
185 #    include <sys/dir.h>
186 #   endif
187 #   if defined(MAGICKCORE_HAVE_NDIR_H)
188 #    include <ndir.h>
189 #   endif
190 #  else
191 #   include <dirent.h>
192 #   define NAMLEN(dirent) strlen((dirent)->d_name)
193 #  endif
194 #  include <sys/wait.h>
195 #  include <pwd.h>
196 # endif
197 # if !defined(S_ISDIR)
198 #  define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
199 # endif
200 # if !defined(S_ISREG)
201 #  define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
202 # endif
203 # include "MagickCore/magick-type.h"
204 # if !defined(MAGICKCORE_WINDOWS_SUPPORT)
205 #  include <sys/time.h>
206 # if defined(MAGICKCORE_HAVE_SYS_TIMES_H)
207 #  include <sys/times.h>
208 # endif
209 # if defined(MAGICKCORE_HAVE_SYS_RESOURCE_H)
210 #  include <sys/resource.h>
211 # endif
212 # if defined(MAGICKCORE_HAVE_SYS_MMAN_H)
213 #  include <sys/mman.h>
214 # endif
215 # if defined(MAGICKCORE_HAVE_SYS_SENDFILE_H)
216 #  include <sys/sendfile.h>
217 # endif
218 # if defined(MAGICKCORE_HAVE_SYS_SOCKET_H)
219 #  include <sys/socket.h>
220 # endif
221 # if defined(MAGICKCORE_HAVE_SYS_UIO_H)
222 #  include <sys/uio.h>
223 # endif
224 #endif
225 #else
226 # include <types.h>
227 # include <stat.h>
228 # include "MagickCore/magick-type.h"
229 #endif
230 
231 #if defined(S_IRUSR) && defined(S_IWUSR)
232 # define S_MODE (S_IRUSR | S_IWUSR)
233 #elif defined (MAGICKCORE_WINDOWS_SUPPORT)
234 # define S_MODE (_S_IREAD | _S_IWRITE)
235 #else
236 # define S_MODE  0600
237 #endif
238 
239 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
240 # include "MagickCore/nt-base.h"
241 #endif
242 #ifdef __VMS
243 # include "MagickCore/vms.h"
244 #endif
245 
246 #undef HAVE_CONFIG_H
247 #undef gamma
248 #undef index
249 #undef pipe
250 #undef y1
251 
252 /*
253   Review these platform specific definitions.
254 */
255 #if defined(MAGICKCORE_POSIX_SUPPORT) &&  !( defined(__OS2__) || defined( vms ) )
256 # define DirectorySeparator  "/"
257 # define DirectoryListSeparator  ':'
258 # define EditorOptions  " -title \"Edit Image Comment\" -e vi"
259 # define Exit  exit
260 # define IsBasenameSeparator(c)  ((c) == '/' ? MagickTrue : MagickFalse)
261 # define X11_PREFERENCES_PATH  "~/."
262 # define ProcessPendingEvents(text)
263 # define ReadCommandlLine(argc,argv)
264 # define SetNotifyHandlers
265 #else
266 # ifdef __VMS
267 #  define X11_APPLICATION_PATH  "decw$system_defaults:"
268 #  define DirectorySeparator  ""
269 #  define DirectoryListSeparator  ';'
270 #  define EditorOptions  ""
271 #  define Exit  exit
272 #  define IsBasenameSeparator(c) \
273   (((c) == ']') || ((c) == ':') || ((c) == '/') ? MagickTrue : MagickFalse)
274 #  define MAGICKCORE_LIBRARY_PATH  "sys$login:"
275 #  define MAGICKCORE_SHARE_PATH  "sys$login:"
276 #  define X11_PREFERENCES_PATH  "decw$user_defaults:"
277 #  define ProcessPendingEvents(text)
278 #  define ReadCommandlLine(argc,argv)
279 #  define SetNotifyHandlers
280 # endif
281 # if defined(__OS2__)
282 #   define DirectorySeparator  "\\"
283 #   define DirectoryListSeparator  ';'
284 # define EditorOptions  " -title \"Edit Image Comment\" -e vi"
285 # define Exit  exit
286 #  define IsBasenameSeparator(c) \
287   (((c) == '/') || ((c) == '\\') ? MagickTrue : MagickFalse)
288 # define PreferencesDefaults  "~\."
289 # define ProcessPendingEvents(text)
290 # define ReadCommandlLine(argc,argv)
291 # define SetNotifyHandlers
292 #endif
293 # if defined(MAGICKCORE_WINDOWS_SUPPORT)
294 #  define DirectorySeparator  "\\"
295 #  define DirectoryListSeparator  ';'
296 #  define EditorOptions ""
297 #  define IsBasenameSeparator(c) \
298   (((c) == '/') || ((c) == '\\') ? MagickTrue : MagickFalse)
299 #  define ProcessPendingEvents(text)
300 #  if !defined(X11_PREFERENCES_PATH)
301 #    define X11_PREFERENCES_PATH  "~\\."
302 #  endif
303 #  define ReadCommandlLine(argc,argv)
304 #  define SetNotifyHandlers \
305     SetErrorHandler(NTErrorHandler); \
306     SetWarningHandler(NTWarningHandler)
307 # endif
308 
309 #endif
310 
311 /*
312   Define system symbols if not already defined.
313 */
314 #if !defined(STDIN_FILENO)
315 #define STDIN_FILENO  0x00
316 #endif
317 
318 #if !defined(O_BINARY)
319 #define O_BINARY  0x00
320 #endif
321 
322 #if !defined(PATH_MAX)
323 #define PATH_MAX  4096
324 #endif
325 
326 #if defined(MAGICKCORE_LTDL_DELEGATE) || (defined(MAGICKCORE_WINDOWS_SUPPORT) && defined(_DLL) && !defined(_LIB))
327 #  define MAGICKCORE_MODULES_SUPPORT
328 #endif
329 
330 #if defined(_MAGICKMOD_)
331 # undef MAGICKCORE_BUILD_MODULES
332 # define MAGICKCORE_BUILD_MODULES
333 #endif
334 
335 /*
336   Magick defines.
337 */
338 #define MagickMaxRecursionDepth  600
339 #define MAGICK_SSIZE_MAX  (SSIZE_MAX)
340 #define MAGICK_SSIZE_MIN  (-(SSIZE_MAX)-1)
341 #define Swap(x,y) ((x)^=(y), (y)^=(x), (x)^=(y))
342 #if defined(_MSC_VER)
343 # define DisableMSCWarning(nr) __pragma(warning(push)) \
344   __pragma(warning(disable:nr))
345 # define RestoreMSCWarning __pragma(warning(pop))
346 #else
347 # define DisableMSCWarning(nr)
348 # define RestoreMSCWarning
349 #endif
350 
351 #if defined(__cplusplus) || defined(c_plusplus)
352 }
353 #endif
354 
355 #endif
356