~ubuntu-branches/ubuntu/gutsy/checkpolicy/gutsy

« back to all changes in this revision

Viewing changes to symtab.c

  • Committer: Bazaar Package Importer
  • Author(s): Russell Coker
  • Date: 2004-05-20 04:32:00 UTC
  • Revision ID: james.westby@ubuntu.com-20040520043200-w4lzkx37dmmc3wt9
Tags: upstream-1.10
ImportĀ upstreamĀ versionĀ 1.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "symtab.h"
 
11
 
 
12
static unsigned int symhash(hashtab_t h, hashtab_key_t key)
 
13
{
 
14
        char *p, *keyp;
 
15
        size_t size;
 
16
        unsigned int val;
 
17
 
 
18
 
 
19
        val = 0;
 
20
        keyp = (char *) key;
 
21
        size = strlen(keyp);
 
22
        for (p = keyp; ((size_t)(p - keyp)) < size; p++)
 
23
                val = (val << 4 | (val >> (8*sizeof(unsigned int)-4))) ^ (*p);
 
24
        return val & (h->size - 1);
 
25
}
 
26
 
 
27
static int symcmp(hashtab_t h __attribute__ ((unused)), hashtab_key_t key1, hashtab_key_t key2)
 
28
{
 
29
        char *keyp1, *keyp2;
 
30
 
 
31
 
 
32
        keyp1 = (char *) key1;
 
33
        keyp2 = (char *) key2;
 
34
        return strcmp(keyp1, keyp2);
 
35
}
 
36
 
 
37
 
 
38
int symtab_init(symtab_t * s, unsigned int size)
 
39
{
 
40
        s->table = hashtab_create(symhash, symcmp, size);
 
41
        if (!s->table)
 
42
                return -1;
 
43
        s->nprim = 0;
 
44
        return 0;
 
45
}
 
46
 
 
47
/* FLASK */
 
48