4 erealloc(void *a, int n)
8 sysfatal("realloc: %r");
17 sysfatal("strdup: %r");
28 sysfatal("malloc: %r");
33 * Custom allocators to avoid malloc overheads on small objects.
34 * We never free these. (See below.)
36 typedef struct Stringtab Stringtab;
48 t = malloc(64*sizeof(Stringtab));
50 sysfatal("out of memory");
67 sysfatal("strdup big string");
72 sysfatal("out of memory");
83 * Return a uniquely allocated copy of a string.
84 * Don't free these -- they stay in the table for the
85 * next caller who wants that particular string.
86 * String comparison can be done with pointer comparison
87 * if you know both strings are atoms.
89 static Stringtab *stab[1024];
98 for(p=(uchar*)s; *p; p++)
109 h = hash(str) % nelem(stab);
110 for(tab=stab[h]; tab; tab=tab->link)
111 if(strcmp(str, tab->str) == 0)
115 tab->str = xstrdup(str);
122 unroot(char *path, char *root)
128 while(len >= 1 && root[len-1]=='/')
130 if(strncmp(path, root, len)==0 && (path[len]=='/' || path[len]=='\0')){