]> Git Repo - linux.git/blame - security/selinux/ss/symtab.c
Merge tag 'pwm/for-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry...
[linux.git] / security / selinux / ss / symtab.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2/*
3 * Implementation of the symbol table type.
4 *
7efbb60b 5 * Author : Stephen Smalley, <[email protected]>
1da177e4
LT
6 */
7#include <linux/kernel.h>
1da177e4
LT
8#include <linux/string.h>
9#include <linux/errno.h>
10#include "symtab.h"
11
24def7bb 12static unsigned int symhash(const void *key)
1da177e4 13{
bb242497 14 const char *p, *keyp;
1da177e4
LT
15 unsigned int size;
16 unsigned int val;
17
18 val = 0;
19 keyp = key;
20 size = strlen(keyp);
21 for (p = keyp; (p - keyp) < size; p++)
22 val = (val << 4 | (val >> (8*sizeof(unsigned int)-4))) ^ (*p);
24def7bb 23 return val;
1da177e4
LT
24}
25
24def7bb 26static int symcmp(const void *key1, const void *key2)
1da177e4 27{
bb242497 28 const char *keyp1, *keyp2;
1da177e4
LT
29
30 keyp1 = key1;
31 keyp2 = key2;
32 return strcmp(keyp1, keyp2);
33}
34
24def7bb
OM
35static const struct hashtab_key_params symtab_key_params = {
36 .hash = symhash,
37 .cmp = symcmp,
38};
1da177e4
LT
39
40int symtab_init(struct symtab *s, unsigned int size)
41{
1da177e4 42 s->nprim = 0;
24def7bb 43 return hashtab_init(&s->table, size);
1da177e4
LT
44}
45
237389e3
OM
46int symtab_insert(struct symtab *s, char *name, void *datum)
47{
24def7bb 48 return hashtab_insert(&s->table, name, datum, symtab_key_params);
237389e3
OM
49}
50
51void *symtab_search(struct symtab *s, const char *name)
52{
24def7bb 53 return hashtab_search(&s->table, name, symtab_key_params);
237389e3 54}
This page took 0.984063 seconds and 4 git commands to generate.