/Proj4/pj_malloc.c

http://github.com/route-me/route-me · C · 28 lines · 17 code · 1 blank · 10 comment · 2 complexity · 0fc638d7bf493aa7bc7f0784c0197660 MD5 · raw file

  1. /* allocate and deallocate memory */
  2. #ifndef lint
  3. static const char SCCSID[]="@(#)pj_malloc.c 4.3 93/06/12 GIE REL";
  4. #endif
  5. /* These routines are used so that applications can readily replace
  6. ** projection system memory allocation/deallocation call with custom
  7. ** application procedures. */
  8. #include "projects.h"
  9. #include <errno.h>
  10. void *
  11. pj_malloc(size_t size) {
  12. // Currently, pj_malloc is a hack to solve an errno problem.
  13. // The problem is described in more details at
  14. // https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=86420.
  15. // It seems, that pj_init and similar functions incorrectly
  16. // (under debian/glibs-2.3.2) assume that pj_malloc resets
  17. // errno after success. pj_malloc tries to mimic this.
  18. int old_errno = errno;
  19. void *res = malloc(size);
  20. if ( res && !old_errno )
  21. errno = 0;
  22. return res;
  23. }
  24. void
  25. pj_dalloc(void *ptr) {
  26. free(ptr);
  27. }