xref: /PHP-7.1/ext/gd/libgd/gdhelpers.h (revision b7a7b1a6)
1 #ifndef GDHELPERS_H
2 #define GDHELPERS_H 1
3 
4 #include <sys/types.h>
5 #include "php.h"
6 
7 /* TBB: strtok_r is not universal; provide an implementation of it. */
8 
9 extern char *gd_strtok_r(char *s, char *sep, char **state);
10 
11 /* These functions wrap memory management. gdFree is
12 	in gd.h, where callers can utilize it to correctly
13 	free memory allocated by these functions with the
14 	right version of free(). */
15 #define gdCalloc(nmemb, size)	ecalloc(nmemb, size)
16 #define gdMalloc(size)		emalloc(size)
17 #define gdRealloc(ptr, size)	erealloc(ptr, size)
18 #define gdEstrdup(ptr)		estrdup(ptr)
19 #define gdFree(ptr)		efree(ptr)
20 #define gdPMalloc(ptr)		pemalloc(ptr, 1)
21 #define gdPFree(ptr)		pefree(ptr, 1)
22 #define gdPEstrdup(ptr)		pestrdup(ptr, 1)
23 
24 /* Returns nonzero if multiplying the two quantities will
25 	result in integer overflow. Also returns nonzero if
26 	either quantity is negative. By Phil Knirsch based on
27 	netpbm fixes by Alan Cox. */
28 
29 int overflow2(int a, int b);
30 
31 #ifdef ZTS
32 #define gdMutexDeclare(x) MUTEX_T x
33 #define gdMutexSetup(x) x = tsrm_mutex_alloc()
34 #define gdMutexShutdown(x) tsrm_mutex_free(x)
35 #define gdMutexLock(x) tsrm_mutex_lock(x)
36 #define gdMutexUnlock(x) tsrm_mutex_unlock(x)
37 #else
38 #define gdMutexDeclare(x)
39 #define gdMutexSetup(x)
40 #define gdMutexShutdown(x)
41 #define gdMutexLock(x)
42 #define gdMutexUnlock(x)
43 #endif
44 
45 #endif /* GDHELPERS_H */
46 
47