/contrib/ntp/libntp/emalloc.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 48 lines · 36 code · 9 blank · 3 comment · 6 complexity · 5f04a29149ea13d89169215bd6917b23 MD5 · raw file

  1. /*
  2. * emalloc - return new memory obtained from the system. Belch if none.
  3. */
  4. #include "ntp_types.h"
  5. #include "ntp_malloc.h"
  6. #include "ntp_syslog.h"
  7. #include "ntp_stdlib.h"
  8. #if defined SYS_WINNT && defined DEBUG
  9. #include <crtdbg.h>
  10. #endif
  11. #if defined SYS_WINNT && defined DEBUG
  12. void *
  13. debug_emalloc(
  14. u_int size,
  15. char *filename,
  16. int line
  17. )
  18. {
  19. char *mem;
  20. if ((mem = (char *)_malloc_dbg(size, _NORMAL_BLOCK, filename, line)) == 0) {
  21. msyslog(LOG_ERR, "Exiting: No more memory!");
  22. exit(1);
  23. }
  24. return mem;
  25. }
  26. #else
  27. void *
  28. emalloc(
  29. u_int size
  30. )
  31. {
  32. char *mem;
  33. if ((mem = (char *)malloc(size)) == 0) {
  34. msyslog(LOG_ERR, "Exiting: No more memory!");
  35. exit(1);
  36. }
  37. return mem;
  38. }
  39. #endif