util.c 902 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include "snap.h"
  13. void*
  14. emalloc(uint32_t n)
  15. {
  16. void *v;
  17. v = malloc(n);
  18. if(v == nil){
  19. fprint(2, "out of memory\n");
  20. exits("memory");
  21. }
  22. memset(v, 0, n);
  23. return v;
  24. }
  25. void*
  26. erealloc(void *v, uint32_t n)
  27. {
  28. v = realloc(v, n);
  29. if(v == nil) {
  30. fprint(2, "out of memory\n");
  31. exits("memory");
  32. }
  33. return v;
  34. }
  35. char*
  36. estrdup(char *s)
  37. {
  38. s = strdup(s);
  39. if(s == nil) {
  40. fprint(2, "out of memory\n");
  41. exits("memory");
  42. }
  43. return s;
  44. }