• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /* Author : Stephen Smalley, <sds@epoch.ncsc.mil> */
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 
symhash(hashtab_t h,hashtab_key_t key)14 static unsigned int symhash(hashtab_t h, hashtab_key_t key)
15 {
16 	char *p, *keyp;
17 	size_t size;
18 	unsigned int val;
19 
20 	val = 0;
21 	keyp = (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 
symcmp(hashtab_t h,hashtab_key_t key1,hashtab_key_t key2)29 static int symcmp(hashtab_t h
30 		  __attribute__ ((unused)), hashtab_key_t key1,
31 		  hashtab_key_t key2)
32 {
33 	char *keyp1, *keyp2;
34 
35 	keyp1 = (char *)key1;
36 	keyp2 = (char *)key2;
37 	return strcmp(keyp1, keyp2);
38 }
39 
symtab_init(symtab_t * s,unsigned int size)40 int 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 
symtab_destroy(symtab_t * s)49 void 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