symtab.c 839 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Implementation of the symbol table type.
  3. *
  4. * Author : Stephen Smalley, <sds@epoch.ncsc.mil>
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/slab.h>
  8. #include <linux/string.h>
  9. #include <linux/errno.h>
  10. #include "symtab.h"
  11. static unsigned int symhash(struct hashtab *h, void *key)
  12. {
  13. char *p, *keyp;
  14. unsigned int size;
  15. unsigned int val;
  16. val = 0;
  17. keyp = key;
  18. size = strlen(keyp);
  19. for (p = keyp; (p - keyp) < size; p++)
  20. val = (val << 4 | (val >> (8*sizeof(unsigned int)-4))) ^ (*p);
  21. return val & (h->size - 1);
  22. }
  23. static int symcmp(struct hashtab *h, void *key1, void *key2)
  24. {
  25. char *keyp1, *keyp2;
  26. keyp1 = key1;
  27. keyp2 = key2;
  28. return strcmp(keyp1, keyp2);
  29. }
  30. int symtab_init(struct symtab *s, unsigned int size)
  31. {
  32. s->table = hashtab_create(symhash, symcmp, size);
  33. if (!s->table)
  34. return -1;
  35. s->nprim = 0;
  36. return 0;
  37. }