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 12#include "private.h" 13 14#include <sepol/policydb/hashtab.h> 15#include <sepol/policydb/symtab.h> 16 17ignore_unsigned_overflow_ 18static unsigned int symhash(hashtab_t h, const_hashtab_key_t key) 19{ 20 const char *p, *keyp; 21 size_t size; 22 unsigned int val; 23 24 val = 0; 25 keyp = (const char *)key; 26 size = strlen(keyp); 27 for (p = keyp; ((size_t) (p - keyp)) < size; p++) 28 val = 29 (val << 4 | (val >> (8 * sizeof(unsigned int) - 4))) ^ (*p); 30 return val & (h->size - 1); 31} 32 33static int symcmp(hashtab_t h 34 __attribute__ ((unused)), const_hashtab_key_t key1, 35 const_hashtab_key_t key2) 36{ 37 return strcmp(key1, key2); 38} 39 40int symtab_init(symtab_t * s, unsigned int size) 41{ 42 s->table = hashtab_create(symhash, symcmp, size); 43 if (!s->table) 44 return -1; 45 s->nprim = 0; 46 return 0; 47} 48 49void symtab_destroy(symtab_t * s) 50{ 51 if (!s) 52 return; 53 if (s->table) 54 hashtab_destroy(s->table); 55 return; 56} 57/* FLASK */ 58