Imported Upstream version 1.9.8
[platform/upstream/doxygen.git] / deps / libmscgen / gdhelpers.h
1 #ifdef __cplusplus
2 extern "C" {
3 #endif
4
5 #ifndef GDHELPERS_H
6 #define GDHELPERS_H 1
7
8         /* sys/types.h is needed for size_t on Sparc-SunOS-4.1 */
9 #ifndef _WIN32_WCE
10 #include <sys/types.h>
11 #else
12 #include <stdlib.h>
13 #endif /* _WIN32_WCE */
14
15         /* TBB: strtok_r is not universal; provide an implementation of it. */
16
17         char * gd_strtok_r (char *s, char *sep, char **state);
18
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
27          * realloc fails */
28         void *gdReallocEx (void *ptr, size_t size);
29
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. */
34
35         int overflow2(int a, int b);
36
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)
44 #elif defined(_WIN32)
45         /* 2.0.18: must include windows.h to get CRITICAL_SECTION. */
46 # include <windows.h>
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)
53 # include <pthread.h>
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)
59 #else
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 */
66
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)
71
72 #endif /* GDHELPERS_H */
73
74 #ifdef __cplusplus
75 }
76 #endif