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