alloc.c 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 <bin.h>
  12. #include <httpd.h>
  13. /*
  14. * memory allocators:
  15. * h routines call canalloc; they should be used by everything else
  16. * note this memory is wiped out at the start of each new request
  17. * note: these routines probably shouldn't fatal.
  18. */
  19. char*
  20. hstrdup(HConnect *c, char *s)
  21. {
  22. char *t;
  23. int n;
  24. n = strlen(s) + 1;
  25. t = binalloc(&c->bin, n, 0);
  26. if(t == nil)
  27. sysfatal("out of memory");
  28. memmove(t, s, n);
  29. return t;
  30. }
  31. void*
  32. halloc(HConnect *c, uint32_t n)
  33. {
  34. void *p;
  35. p = binalloc(&c->bin, n, 1);
  36. if(p == nil)
  37. sysfatal("out of memory");
  38. return p;
  39. }