libgd/src/gdhelpers.h

77 lines
2.3 KiB
C
Raw Permalink Normal View History

#ifndef GDHELPERS_H
#define GDHELPERS_H 1
2006-04-05 08:54:20 -07:00
#ifdef __cplusplus
extern "C" {
#endif
2013-04-03 05:23:11 -07:00
/* sys/types.h is needed for size_t on Sparc-SunOS-4.1 */
2007-04-29 20:55:11 -07:00
#ifndef _WIN32_WCE
2006-04-05 08:44:17 -07:00
#include <sys/types.h>
2007-04-29 20:55:11 -07:00
#else
#include <stdlib.h>
#endif /* _WIN32_WCE */
2006-04-05 08:44:17 -07:00
2013-04-03 05:23:11 -07:00
/* TBB: strtok_r is not universal; provide an implementation of it. */
2006-04-05 08:41:55 -07:00
2021-05-28 12:45:06 -07:00
char *gd_strtok_r(char *s, const char *sep, char **state);
2006-04-05 08:41:55 -07:00
2013-04-03 05:23:11 -07:00
/* These functions wrap memory management. gdFree is
in gd.h, where callers can utilize it to correctly
free memory allocated by these functions with the
right version of free(). */
void *gdCalloc(size_t nmemb, size_t size) BGD_MALLOC;
void *gdMalloc(size_t size) BGD_MALLOC;
2013-06-10 05:53:45 -07:00
void *gdRealloc (void *ptr, size_t size);
/* The extended version of gdReallocEx will free *ptr if the
* realloc fails */
2013-06-10 05:53:45 -07:00
void *gdReallocEx (void *ptr, size_t size);
2006-04-05 08:41:55 -07:00
2013-04-03 05:23:11 -07:00
/* Returns nonzero if multiplying the two quantities will
result in integer overflow. Also returns nonzero if
either quantity is negative. By Phil Knirsch based on
netpbm fixes by Alan Cox. */
2006-04-05 08:54:20 -07:00
2013-04-03 05:23:11 -07:00
int overflow2(int a, int b);
2006-04-05 08:54:20 -07:00
2013-04-03 05:23:11 -07:00
/* 2.0.16: portable mutex support for thread safety. */
#if defined(CPP_SHARP)
# define gdMutexDeclare(x)
# define gdMutexSetup(x)
# define gdMutexShutdown(x)
# define gdMutexLock(x)
# define gdMutexUnlock(x)
#elif defined(_WIN32)
2013-04-03 05:23:11 -07:00
/* 2.0.18: must include windows.h to get CRITICAL_SECTION. */
# include <windows.h>
# define gdMutexDeclare(x) CRITICAL_SECTION x
# define gdMutexSetup(x) InitializeCriticalSection(&x)
# define gdMutexShutdown(x) DeleteCriticalSection(&x)
# define gdMutexLock(x) EnterCriticalSection(&x)
# define gdMutexUnlock(x) LeaveCriticalSection(&x)
#elif defined(HAVE_PTHREAD)
# include <pthread.h>
# define gdMutexDeclare(x) pthread_mutex_t x
# define gdMutexSetup(x) pthread_mutex_init(&x, 0)
# define gdMutexShutdown(x) pthread_mutex_destroy(&x)
# define gdMutexLock(x) pthread_mutex_lock(&x)
# define gdMutexUnlock(x) pthread_mutex_unlock(&x)
2006-04-05 08:49:38 -07:00
#else
# define gdMutexDeclare(x)
# define gdMutexSetup(x)
# define gdMutexShutdown(x)
# define gdMutexLock(x)
# define gdMutexUnlock(x)
#endif /* _WIN32 || HAVE_PTHREAD */
2006-04-05 08:49:38 -07:00
#define DPCM2DPI(dpcm) (unsigned int)((dpcm)*2.54 + 0.5)
#define DPM2DPI(dpm) (unsigned int)((dpm)*0.0254 + 0.5)
#define DPI2DPCM(dpi) (unsigned int)((dpi)/2.54 + 0.5)
#define DPI2DPM(dpi) (unsigned int)((dpi)/0.0254 + 0.5)
2006-04-05 08:54:20 -07:00
#ifdef __cplusplus
}
#endif
#endif /* GDHELPERS_H */