Back to index

tetex-bin  3.0
gdhelpers.h
Go to the documentation of this file.
00001 #ifdef __cplusplus
00002 extern "C" {
00003 #endif
00004 
00005 #ifndef GDHELPERS_H
00006 #define GDHELPERS_H 1
00007 
00008 /* sys/types.h is needed for size_t on Sparc-SunOS-4.1 */
00009 #include <sys/types.h>
00010 
00011 /* TBB: strtok_r is not universal; provide an implementation of it. */
00012 
00013  char * gd_strtok_r (char *s, char *sep, char **state);
00014 
00015 /* These functions wrap memory management. gdFree is
00016        in gd.h, where callers can utilize it to correctly
00017        free memory allocated by these functions with the
00018        right version of free(). */
00019 void *gdCalloc (size_t nmemb, size_t size);
00020 void *gdMalloc (size_t size);
00021 void *gdRealloc (void *ptr, size_t size);
00022 
00023 /* Returns nonzero if multiplying the two quantities will
00024        result in integer overflow. Also returns nonzero if 
00025        either quantity is negative. By Phil Knirsch based on
00026        netpbm fixes by Alan Cox. */
00027 
00028 int overflow2(int a, int b);
00029 
00030 /* 2.0.16: portable mutex support for thread safety. */
00031 
00032 #ifdef WIN32
00033 /* 2.0.18: must include windows.h to get CRITICAL_SECTION. */
00034 #include <windows.h>
00035 #define gdMutexDeclare(x) CRITICAL_SECTION x
00036 #define gdMutexSetup(x) InitializeCriticalSection(&x)
00037 #define gdMutexShutdown(x) DeleteCriticalSection(&x)
00038 #define gdMutexLock(x) EnterCriticalSection(&x)
00039 #define gdMutexUnlock(x) LeaveCriticalSection(&x)
00040 #else
00041 #ifdef HAVE_PTHREAD
00042 #include <pthread.h>
00043 #define gdMutexDeclare(x) pthread_mutex_t x
00044 #define gdMutexSetup(x) pthread_mutex_init(&x, 0)
00045 #define gdMutexShutdown(x) pthread_mutex_destroy(&x)
00046 #define gdMutexLock(x) pthread_mutex_lock(&x)
00047 #define gdMutexUnlock(x) pthread_mutex_unlock(&x)
00048 #else
00049 #define gdMutexDeclare(x)
00050 #define gdMutexSetup(x) 
00051 #define gdMutexShutdown(x) 
00052 #define gdMutexLock(x) 
00053 #define gdMutexUnlock(x) 
00054 #endif /* HAVE_PTHREAD */
00055 #endif /* WIN32 */
00056 
00057 #endif /* GDHELPERS_H */
00058 
00059 #ifdef __cplusplus
00060 }
00061 #endif