1 2 /* Author : Stephen Smalley, <sds@tycho.nsa.gov> */ 3 4 /* FLASK */ 5 6 /* 7 * Implementation of the symbol table type. 8 */ 9 10 #include <string.h> 11 #include <sepol/policydb/hashtab.h> 12 #include <sepol/policydb/symtab.h> 13 14 static unsigned int symhash(hashtab_t h, const_hashtab_key_t key) 15 { 16 const char *p, *keyp; 17 size_t size; 18 unsigned int val; 19 20 val = 0; 21 keyp = (const char *)key; 22 size = strlen(keyp); 23 for (p = keyp; ((size_t) (p - keyp)) < size; p++) 24 val = 25 (val << 4 | (val >> (8 * sizeof(unsigned int) - 4))) ^ (*p); 26 return val & (h->size - 1); 27 } 28 29 static int symcmp(hashtab_t h 30 __attribute__ ((unused)), const_hashtab_key_t key1, 31 const_hashtab_key_t key2) 32 { 33 return strcmp(key1, key2); 34 } 35 36 int symtab_init(symtab_t * s, unsigned int size) 37 { 38 s->table = hashtab_create(symhash, symcmp, size); 39 if (!s->table) 40 return -1; 41 s->nprim = 0; 42 return 0; 43 } 44 45 void symtab_destroy(symtab_t * s) 46 { 47 if (!s) 48 return; 49 if (s->table) 50 hashtab_destroy(s->table); 51 return; 52 } 53 /* FLASK */ 54