alloc.c 600 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bin.h>
  4. #include <httpd.h>
  5. /*
  6. * memory allocators:
  7. * h routines call canalloc; they should be used by everything else
  8. * note this memory is wiped out at the start of each new request
  9. * note: these routines probably shouldn't fatal.
  10. */
  11. char*
  12. hstrdup(HConnect *c, char *s)
  13. {
  14. char *t;
  15. int n;
  16. n = strlen(s) + 1;
  17. t = binalloc(&c->bin, n, 0);
  18. if(t == nil)
  19. sysfatal("out of memory");
  20. memmove(t, s, n);
  21. return t;
  22. }
  23. void*
  24. halloc(HConnect *c, ulong n)
  25. {
  26. void *p;
  27. p = binalloc(&c->bin, n, 1);
  28. if(p == nil)
  29. sysfatal("out of memory");
  30. return p;
  31. }