split well-used utility functions into util.c

This commit is contained in:
Ron Pedde 2006-07-12 04:39:11 +00:00
parent 7a3a5ce3af
commit 26e4259332
2 changed files with 59 additions and 0 deletions

35
src/util.c Normal file
View File

@ -0,0 +1,35 @@
/*
* simple utility functions
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
uint32_t util_djb_hash_block(unsigned char *data, uint32_t len) {
uint32_t hash = 5381;
unsigned char *pstr = data;
while(len--) {
hash = ((hash << 5) + hash) + *pstr;
pstr++;
}
return hash;
}
uint32_t util_djb_hash_str(char *str) {
uint32_t len;
len = strlen(str);
return util_djb_hash_block((unsigned char *)str,len);
}

24
src/util.h Normal file
View File

@ -0,0 +1,24 @@
/*
* simple utility functions
*/
#ifndef _UTIL_H_
#define _UTIL_H_
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#include <sys/types.h>
/* simple hashing functions */
extern uint32_t util_djb_hash_block(unsigned char *data, uint32_t len);
extern uint32_t util_djb_hash_str(char *str);
#endif /* _UTIL_H_ */