smballoc.c 929 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "headers.h"
  10. #ifndef LEAK
  11. void *
  12. smbemallocz(uint32_t size, int clear)
  13. {
  14. void *p = nbemalloc(size);
  15. if (clear && p)
  16. memset(p, 0, size);
  17. return p;
  18. }
  19. void *
  20. smbemalloc(uint32_t size)
  21. {
  22. return smbemallocz(size, 0);
  23. }
  24. char *
  25. smbestrdup(char *p)
  26. {
  27. char *q;
  28. q = smbemalloc(strlen(p) + 1);
  29. return strcpy(q, p);
  30. }
  31. #endif
  32. void
  33. smbfree(void **pp)
  34. {
  35. void *p = *pp;
  36. if (p) {
  37. free(p);
  38. *pp = nil;
  39. }
  40. }
  41. void
  42. smberealloc(void **pp, uint32_t size)
  43. {
  44. *pp = realloc(*pp, size);
  45. assert(size == 0 || *pp);
  46. }