aux.c 699 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <auth.h>
  4. #include <fcall.h>
  5. #include <thread.h>
  6. #include "9p.h"
  7. void*
  8. emalloc9p(ulong sz)
  9. {
  10. void *v;
  11. if((v = malloc(sz)) == nil) {
  12. fprint(2, "out of memory allocating %lud\n", sz);
  13. exits("mem");
  14. }
  15. memset(v, 0, sz);
  16. setmalloctag(v, getcallerpc(&sz));
  17. return v;
  18. }
  19. void*
  20. erealloc9p(void *v, ulong sz)
  21. {
  22. if((v = realloc(v, sz)) == nil) {
  23. fprint(2, "out of memory allocating %lud\n", sz);
  24. exits("mem");
  25. }
  26. setrealloctag(v, getcallerpc(&v));
  27. return v;
  28. }
  29. char*
  30. estrdup9p(char *s)
  31. {
  32. char *t;
  33. if((t = strdup(s)) == nil) {
  34. fprint(2, "out of memory in strdup(%.10s)\n", s);
  35. exits("mem");
  36. }
  37. setmalloctag(t, getcallerpc(&s));
  38. return t;
  39. }