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