1 /*
2  * Implementation of the symbol table type.
3  *
4  * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
5  */
6 
7 /* Ported to Xen 3.0, George Coker, <gscoker@alpha.ncsc.mil> */
8 
9 #include <xen/lib.h>
10 #include <xen/xmalloc.h>
11 #include <xen/string.h>
12 #include <xen/errno.h>
13 #include "symtab.h"
14 
symhash(struct hashtab * h,const void * key)15 static unsigned int symhash(struct hashtab *h, const void *key)
16 {
17     const char *p, *keyp;
18     unsigned int size;
19     unsigned int val;
20 
21     val = 0;
22     keyp = key;
23     size = strlen(keyp);
24     for ( p = keyp; (p - keyp) < size; p++ )
25         val = (val << 4 | (val >> (8*sizeof(unsigned int)-4))) ^ (*p);
26     return val & (h->size - 1);
27 }
28 
symcmp(struct hashtab * h,const void * key1,const void * key2)29 static int symcmp(struct hashtab *h, const void *key1, const void *key2)
30 {
31     const char *keyp1, *keyp2;
32 
33     keyp1 = key1;
34     keyp2 = key2;
35     return strcmp(keyp1, keyp2);
36 }
37 
38 
symtab_init(struct symtab * s,unsigned int size)39 int symtab_init(struct symtab *s, unsigned int size)
40 {
41     s->table = hashtab_create(symhash, symcmp, size);
42     if ( !s->table )
43         return -1;
44     s->nprim = 0;
45     return 0;
46 }
47 
48