8 /* sys/types.h is needed for size_t on Sparc-SunOS-4.1 */
10 #include <sys/types.h>
13 #endif /* _WIN32_WCE */
15 /* TBB: strtok_r is not universal; provide an implementation of it. */
17 char * gd_strtok_r (char *s, char *sep, char **state);
19 /* These functions wrap memory management. gdFree is
20 in gd.h, where callers can utilize it to correctly
21 free memory allocated by these functions with the
22 right version of free(). */
23 void *gdCalloc (size_t nmemb, size_t size);
24 void *gdMalloc (size_t size);
25 void *gdRealloc (void *ptr, size_t size);
26 /* The extended version of gdReallocEx will free *ptr if the
28 void *gdReallocEx (void *ptr, size_t size);
30 /* Returns nonzero if multiplying the two quantities will
31 result in integer overflow. Also returns nonzero if
32 either quantity is negative. By Phil Knirsch based on
33 netpbm fixes by Alan Cox. */
35 int overflow2(int a, int b);
37 /* 2.0.16: portable mutex support for thread safety. */
38 #if defined(CPP_SHARP)
39 # define gdMutexDeclare(x)
40 # define gdMutexSetup(x)
41 # define gdMutexShutdown(x)
42 # define gdMutexLock(x)
43 # define gdMutexUnlock(x)
45 /* 2.0.18: must include windows.h to get CRITICAL_SECTION. */
47 # define gdMutexDeclare(x) CRITICAL_SECTION x
48 # define gdMutexSetup(x) InitializeCriticalSection(&x)
49 # define gdMutexShutdown(x) DeleteCriticalSection(&x)
50 # define gdMutexLock(x) EnterCriticalSection(&x)
51 # define gdMutexUnlock(x) LeaveCriticalSection(&x)
52 #elif defined(HAVE_PTHREAD)
54 # define gdMutexDeclare(x) pthread_mutex_t x
55 # define gdMutexSetup(x) pthread_mutex_init(&x, 0)
56 # define gdMutexShutdown(x) pthread_mutex_destroy(&x)
57 # define gdMutexLock(x) pthread_mutex_lock(&x)
58 # define gdMutexUnlock(x) pthread_mutex_unlock(&x)
60 # define gdMutexDeclare(x)
61 # define gdMutexSetup(x)
62 # define gdMutexShutdown(x)
63 # define gdMutexLock(x)
64 # define gdMutexUnlock(x)
65 #endif /* _WIN32 || HAVE_PTHREAD */
67 #define DPCM2DPI(dpcm) (unsigned int)((dpcm)*2.54 + 0.5)
68 #define DPM2DPI(dpm) (unsigned int)((dpm)*0.0254 + 0.5)
69 #define DPI2DPCM(dpi) (unsigned int)((dpi)/2.54 + 0.5)
70 #define DPI2DPM(dpi) (unsigned int)((dpi)/0.0254 + 0.5)
72 #endif /* GDHELPERS_H */