debuggers.hg

view xen/xsm/flask/ss/symtab.c @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children b22f9ab1716a
line source
1 /*
2 * Implementation of the symbol table type.
3 *
4 * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
5 */
7 /* Ported to Xen 3.0, George Coker, <gscoker@alpha.ncsc.mil> */
9 #include <xen/lib.h>
10 #include <xen/xmalloc.h>
11 #include <xen/string.h>
12 #include <xen/errno.h>
13 #include "symtab.h"
15 static unsigned int symhash(struct hashtab *h, void *key)
16 {
17 char *p, *keyp;
18 unsigned int size;
19 unsigned int val;
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 }
29 static int symcmp(struct hashtab *h, void *key1, void *key2)
30 {
31 char *keyp1, *keyp2;
33 keyp1 = key1;
34 keyp2 = key2;
35 return strcmp(keyp1, keyp2);
36 }
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 }