util.c 569 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <draw.h>
  4. #include <plumb.h>
  5. #include "faces.h"
  6. void*
  7. emalloc(ulong sz)
  8. {
  9. void *v;
  10. v = malloc(sz);
  11. if(v == nil) {
  12. fprint(2, "out of memory allocating %ld\n", sz);
  13. exits("mem");
  14. }
  15. memset(v, 0, sz);
  16. return v;
  17. }
  18. void*
  19. erealloc(void *v, ulong sz)
  20. {
  21. v = realloc(v, sz);
  22. if(v == nil) {
  23. fprint(2, "out of memory allocating %ld\n", sz);
  24. exits("mem");
  25. }
  26. return v;
  27. }
  28. char*
  29. estrdup(char *s)
  30. {
  31. char *t;
  32. if((t = strdup(s)) == nil) {
  33. fprint(2, "out of memory in strdup(%.10s)\n", s);
  34. exits("mem");
  35. }
  36. return t;
  37. }