gdhelpers.h 1.5 KB

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